Home  >  Article  >  Web Front-end  >  javascript date and time conversion method_javascript skills

javascript date and time conversion method_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:41:481163browse

If you use Microsoft's Json serialization library, the date will be

Copy the code The code is as follows:

/Date(1224043200000)/
The effective approach is

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" );

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn