最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Want to get Timezone using jquery - Stack Overflow

programmeradmin7浏览0评论

In jquery,

var date = new Date();

It is taking system Date Not site Time zone

var date = (new Date()).getTimezoneOffset();

it is also not working.please anyone help for this.thank you.

In jquery,

var date = new Date();

It is taking system Date Not site Time zone

var date = (new Date()).getTimezoneOffset();

it is also not working.please anyone help for this.thank you.

Share Improve this question edited May 22, 2015 at 6:52 Barmar 784k57 gold badges548 silver badges660 bronze badges asked May 22, 2015 at 6:51 abc123abc123 211 silver badge2 bronze badges 3
  • It's supposed to use the system time zone. What other time zone would it use? – Barmar Commented May 22, 2015 at 6:53
  • 2 What does jQuery have to do with this? This is just plain Javascript, there are no date functions in jQuery. – Barmar Commented May 22, 2015 at 6:54
  • 1 Javascript runs on the client machine, it doesn't know anything about the server. If you want the server time, get the date in a PHP script on the server. – Barmar Commented May 22, 2015 at 6:55
Add a ment  | 

2 Answers 2

Reset to default 3

jQuery has only one date/time function, which is $.now()

If you meant JavaScript, the answer is still no. You can only obtain a time zone offset from date.getTimezoneOffset(). You can't get a time zone - at least not in all browsers.

You can guess at the time zone, by using the jsTimeZoneDetect library, but it is just a guess. It may or may not be accurate.

If you can guarantee your users are running a browser that supports the brand new ECMAScript Internationalization API, you can get the user's time zone with:

Intl.DateTimeFormat().resolvedOptions().timeZone

Return the timezone difference between UTC and Local Time:

var d = new Date()
var n = d.getTimezoneOffset();

The result n will be: -300

The getTimezoneOffset() method returns the time difference between UTC time and local time, in minutes.

For example, If your time zone is GMT+2, -120 will be returned.

Note: The returned value is not a constant, because of the practice of using Daylight Saving Time.

Tip: The Universal Coordinated Time (UTC) is the time set by the World Time Standard.

Note: UTC time is the same as GMT time.

发布评论

评论列表(0)

  1. 暂无评论