0

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)/"?

3
  • So you want to convert from dd.MM.yyyy HH:mm to "/Date(1391160281569)/" using javascript? Commented Feb 7, 2014 at 9:30
  • is dd.MM.yyyy HH:mm a string dataType? or Date object? Commented Feb 7, 2014 at 9:30
  • A string, but i can easily obtain a date, it that facilitates the work :) Commented Feb 7, 2014 at 9:31

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

You can use split with regular expressions. date.split(/[:. ]/) would give you ["31", "01", "2014", "11", "24"]
@tewathia Thanks, I didn't know about it. I have included in my answer.
0

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.

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.