Use JS to parse the datetime type data of C # after JSON serialization(2012-09-21 19:36:03)
reproduced
Tags: gossip |
Category: javascript |
Val is the data of the DateTime type of C # that is directly serialized by JSON
Function Formattime (val) {
var re =/-?\d+/;
var m = re.exec (val);
var d = new Date (parseint (m[0));
Return date as "2012-02-13-09:09:09" format
Return D.format ("Yyyy-mm-dd hh:mm:ss");
}
Used to format date display
"Thank you for crossing the http://www.cnblogs.com/farawayboat/archive/2011/03/17/1987408.html."
Displays the datetime type data for the JSON serialized C # directly, possibly similar to the following:
\/date (1245398693390) \
The number in parentheses is the number of milliseconds that elapsed since 00:00:00 on January 1, 1970 and the time that DateTime represents, so
We can use a regular expression to extract it and construct a JavaScript Date object:
Date.prototype.format = function (format)//author:meizz
{
var o = {
"m+": This.getmonth () + 1,//month
"D+": This.getdate (),//day
"H +": this.gethours (),//hour
"m+": This.getminutes (),//minute
"S+": This.getseconds (),//second
"q+": Math.floor ((This.getmonth () + 3)/3),//quarter
"S": This.getmilliseconds ()//millisecond
}
if (/(y+)/.test (format)) format = Format.replace (regexp.$1,
(This.getfullyear () + ""). substr (4-regexp.$1.length));
For (var k in O) if (New RegExp ("(" + K + ")"). Test (format))
Format = Format.replace (regexp.$1,
Regexp.$1.length = = 1? O[K]:
("XX" + o[k]). substr (("" + o[k]). length);
return format;
}