我刚刚意识到,使用 Javascript 的 Date 对象获取日期可能会根据用户的浏览器/计算机返回不同的结果。是这种情况还是 Javascript 总是以某种方式返回实际时间,而不管用户计算机的设置如何?
最佳答案
是的,它根据用户系统日期返回日期:
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.
关于javascript - Javascript 的 Date 对象依赖于用户的浏览器吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17513680/