Reputation: 26085
I just realized that using Javascript's Date object to get the date may return different results depending on the user's browser/computer. Is this the case or does Javascript somehow always returns the actual time, regardless of the user's computer's settings?
Upvotes: 2
Views: 2711
Reputation: 23472
Different browser implementations should support standard Date object requirements, but some have bugs and some have taken the capabilities further than others. Current time taken from the computer's system time is of course out of your control. Take a look at moments.js. It's a nice little library that deals with such intricacies that you do have control over.
A 5.5kb javascript date library for parsing, validating, manipulating, and formatting dates.
Upvotes: 0
Reputation: 10619
Yes, it returns Date as per Users System date:
The Date object enables the JavaScript developer to create a Date object initialized to a specific time and date, or to create a date object that reflects the current system time on the computer on which the browser is running. There are two important things to note when working with the JavaScript Date object. Firstly, when reading the date and time of the user's computer you are completely at the mercy of the user's ability to set and maintain the correct day and time on their computer. Secondly, whilst you can read the system date and time set on the user's computer, and change those settings within your Date object instance, you cannot change the computer's system date and time. No matter what methods you call or properties you change on your Date object, the user's system date and time remain unaltered.
http://www.techotopia.com/index.php/JavaScript_Date_Object
Upvotes: 3
Reputation: 64526
Yes it is entirely dependent on the user's local system time.
If you want to work with the server time, you can always populate the date object with some server side code that prints the current server time.
Upvotes: 0
Reputation: 15724
Yes. Javascript (generally) runs on the Client side. Anything it does will likely be relative to the clients machine. In this case, the system clock (not the browser AFAIK)
Upvotes: 0