简体   繁体   中英

Convert datetime object into specific string Javascript

I have a date in the format dd.MM.yyyy HH:mm , for example 31.01.2014 11:24. How can I obtain, in javascript, the string "/Date(1391160281569)/"?

Here is an approach

var date = "31.01.2014 11:24";
var sp1 = date.split(/[:. ]/);
var newDate = new Date(sp1[2], (+sp1[1] - 1), sp1[0], sp1[3], sp1[4]);
var milliSeconds = newDate.getTime();
var urFormat = "/Date(" + milliSeconds + ")/";
alert(urFormat)

JSFiddle

I took me a while but i got this:

var theStringVersion = "/Date("+$.now()+")/";

Of course, for a real date, i would have to get the timestamp for it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM