Home > Article > Web Front-end > javascript date and time conversion method_javascript skills
If you use Microsoft's Json serialization library, the date will be
mydate.replace(//Date((.*?))//gi, "new Date($1)");
If you want to convert the format, it is best to write an extension method:
Date.prototype.pattern=function(fmt) { , //Day " 🎜> "m " : this.getMinutes(), //Minutes "
"s " : this.getSeconds(), //Seconds
"q " : Math.floor((this.getMonth() 3) /3), //Quarter "S": this.getMilliseconds() . 🎜> " 1 ":"/u4e00 ",
" 2 ":"/u4e8c ",
" 3 ":"/u4e09 ",
" 4 ":/u56db",
"5" : "/u4e94", gExp. $1, (this.getFullYear() "").substr(4 - RegExp.$1.length)); fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "/u661f/u671f" : "/u5468") : "") week[this.getDay( ) ""]);
} for(var k in o){
if(new RegExp("(" k ")").test(fmt)){
fmt = fmt .replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00" o[k]).substr(("" o[k]).length)) );
The conversion is as follows:
var nDate=mydate.replace(//Date((.*?))//gi, "new Date($1)");
nDate.pattern("yyyy-MM-dd hh:mm" );