AnuragD
AnuragD

Reputation: 327

Does javascript new Date(timestamp) return date according to client's timezone?

I have a situation when i retrieve a timestamp from the server and use the following :-

var x = new Date(timestamp);

Does x give the time as per the client's timezone ?

Upvotes: 0

Views: 169

Answers (2)

basilikum
basilikum

Reputation: 10528

First of all you have to ensure that the timestamp you put in the new Date() constructor is in Unix Time and in miliseconds, which is not always the case when you get the timestamp from a sever.

Next, the acutal Date object will just store this timestamp and provides some methods to transform it and to display it in a human readable form. Just take a look at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date and try some things for yourself. One thing that it definitely does is using the correct client timezone in the toString() method:

var x = new Date(timestamp);
console.log(x); //Sat Jun 01 2013 18:00:12 GMT+0200 (Mitteleuropäische Sommerzeit)
                //that was the result for my timezone

Upvotes: 2

CoursesWeb
CoursesWeb

Reputation: 4237

I think it gives the time according to timezone set in the client operation system.

Upvotes: 0

Related Questions