Datetime 轉字串
字串轉Datetime
//字串轉DateTime
function convStrToDate(dateStr) {
var parseDateObj = parseDate(dateStr); //.replace(/-/g,"/");
// $.console("parse:" + parseDateObj);
var convDate = new Date(Date.parse(parseDateObj));
return convDate;
}
function parseDate(dateStr) {
var a = $.map(dateStr.split(/[^0-9]/), function (s) {
return parseInt(s, 10)
});
return new Date(a[0], a[1] - 1 || 0, a[2] || 1, a[3] || 0, a[4] || 0, a[5] || 0, a[6] || 0);
}
//DateTime轉字串
function convDateToStr(dateObj) {
var year = dateObj.getFullYear();
if (dateObj.getMonth() + 1 > 9)
{ var month = dateObj.getMonth() + 1; }
else
{
var month = dateObj.getMonth() + 1;
month = "0" + month;
}
if (dateObj.getDate() > 9)
{ var date = dateObj.getDate(); }
else
{
var date = dateObj.getDate();
date = "0" + date;
}
var hour = dateObj.getHours();
var minute = dateObj.getMinutes();
var second = dateObj.getSeconds();
return year + "/" + month + "/" + date;
}