wcf - Converting a .NET DateTime to a Javascript Date -
i have wcf service serves dates javascript. want manipulate date, arrives in javascript looking this:
/date(1361145600000+0000)/
i know miliseconds since 1970/01/01, havent been able figure out how convert javascript date.
do need utilize regex or trim text extract miliseconds, , utilize this:
new date(miliseconds)
surely there must easier way?
if '+0000' standard timezone offset, first 2 digits hours, lastly two, minutes.
presumably not '0000'-
you need add(or subtract) milliseconds difference utc first integral part homecoming right date.
function timeconvert(ds){ var d, dtime, t, tz, off, dobj= ds.match(/(\d+)|([+-])|(\d{4})/g); t= parseint(dobj[0]); tz= dobj[1]; off= dobj[2]; if(off){ off= (parseint(off.substring(0, 2), 10)*3600000)+ (parseint(off.substring(2), 10)*60000); if(tz== '-') off*= -1; } else off= 0; homecoming new date(t+= off).toutcstring(); } timeconvert('date(1361145600000)+0000');
//returned value: (string utc)
mon, 18 feb 2013 00:00:00 gmt
if dates are in utc ('+0000') can pull important digits string-
function timeconvert(ds){ var d=ds.match(/(\d+)/)[1]; homecoming new date(+d).toutcstring(); } timeconvert('date(1361145600000)+0000)'); // returned value: (string utc) mon, 18 feb 2013 00:00:00 gmt
javascript wcf date datetime
No comments:
Post a Comment