Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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)/"?
dd.MM.yyyy HH:mm
"/Date(1391160281569)/"
Date
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
Add a comment
split
date.split(/[:. ]/)
["31", "01", "2014", "11", "24"]
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.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
dd.MM.yyyy HH:mmto"/Date(1391160281569)/"using javascript?dd.MM.yyyy HH:mma string dataType? orDateobject?