Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
188
rated 0 times [  194] [ 6]  / answers: 1 / hits: 141870  / 11 Years ago, fri, june 7, 2013, 12:00:00

I have something like /Date(1370001284000+0200)/ as timestamp. I guess it is a unix date, isn't it? How can I convert this to a date like this: 31.05.2013 13:54:44



I tried THIS converter for 1370001284 and it gives the right date. So it is in seconds.



But I still get the wrong date for:



var substring = unix_timestamp.replace(/Date(, );
substring = substring.replace(000+0200)/, );
var date = new Date();
date.setSeconds(substring);
return date;

More From » date

 Answers
5

Note my use of t.format comes from using Moment.js, it is not part of JavaScript's standard Date prototype.



A Unix timestamp is the number of seconds since 1970-01-01 00:00:00 UTC.


The presence of the +0200 means the numeric string is not a Unix timestamp as it contains timezone adjustment information. You need to handle that separately.


If your timestamp string is in milliseconds, then you can use the milliseconds constructor and Moment.js to format the date into a string:


var t = new Date( 1370001284000 );
var formatted = moment(t).format("dd.mm.yyyy hh:MM:ss");

If your timestamp string is in seconds, then use setSeconds:


var t = new Date();
t.setSeconds( 1370001284 );
var formatted = moment(t).format("dd.mm.yyyy hh:MM:ss");

[#77761] Wednesday, June 5, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nellykaliae

Total Points: 119
Total Questions: 95
Total Answers: 103

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;