Convert to Date() default format
var parserDate = function (date) {
var t = Date.parse(date);
if (!isNaN(t)) {
return new Date(Date.parse(date.replace(/-/g, "/")));
} else {
Return New Date ();
##} }##//Sat Jun 10 2017 13:59:46 GMT+0800 (China Standard Time)
Convert to common formatvar formatDate = function (date) { var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? ( '0' + m) : m;
var d = date.getDate();
d = d < 10 ? ('0' + d) : d;
var h = date.getHours();
h = h< 10 ? ('0' + h) : h;
var minute = date.getMinutes();
minute = minute < 10 ? ('0' + minute) : minute;
var second=date.getSeconds();
second=second<10?( '0'+second):second;
return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
};
var a=new Date();
formatDate (a);
//"2017-06-10 14:02:27"
The above is the detailed content of Date() date format conversion example code. For more information, please follow other related articles on the PHP Chinese website!