0

I have data look like this ( /Date(1500921000000)/ ) and I want to convert into Date. How IDK. help me, please

3
  • 1
    What does your data looks like, is it string? Commented Jul 29, 2017 at 10:56
  • For miliseconds to readable date / time string, I am using momentjs.org - for eample: moment(1500921000000).format('MMMM Do YYYY, h:mm:ss a') will return string like this: July 29th 2017, 1:05:28 pm Commented Jul 29, 2017 at 11:05
  • In JS new Date(1500921000000) already gives you the according date object. Commented Jul 29, 2017 at 11:08

1 Answer 1

0

You can try this code

//DEFINE THE FUNCTION TO GET DATE FROM MILISECOND var format = function (time, format) { var t = new Date(time); var tf = function (i) { return (i < 10 ? '0' : '') + i }; return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) { switch (a) { case 'yyyy': return tf(t.getFullYear()); break; case 'MM': return tf(t.getMonth() + 1); break; case 'mm': return tf(t.getMinutes()); break; case 'dd': return tf(t.getDate()); break; case 'HH': return tf(t.getHours()); break; case 'ss': return tf(t.getSeconds()); break; } }) } //ALERT THE OUTPUT OF "1500921000000" MILISECOND alert(format(new Date(1500921000000).getTime(), 'MM/dd/yyyy')) 

try that then let me know the result, Thanks

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.