Javascript set timezone in date object itself like setTimeOffset() [duplicate]

試著忘記壹切 提交于 2019-12-20 07:52:05

问题


I want to change timezone in Date object itself, because device(web browser?) itself doesn't support timezone.

How I change it?

For example:

var date = new Date();
// Value is "Mon Jun 19 2017 10:00:08 GMT+0000 (GMT)"
date.setTimezoneOffset("+09.00"); // For example
// Value is "Mon Jun 19 2017 01:00:08 GMT+0900 (GMT)"

I don't want to use like this:

var date = new Date();
// Value is "Mon Jun 19 2017 10:00:08 GMT+0000 (GMT)"    
date.setTimezoneOffset("+09.00"); // For example
// Value is "Mon Jun 19 2017 01:00:08 GMT+0000 (GMT)"

Thanks.


回答1:


I want to change timezone in Date object itself, because device(web browser?) itself doesn't support timezone.

How I change it?

You can't. The ECMAScript Date object doesn't have a timezone, it's UTC internally. The offset is supplied by the host system.

If you want to support different time zones, write your own functions or use a library that supports them.



来源:https://stackoverflow.com/questions/44623363/javascript-set-timezone-in-date-object-itself-like-settimeoffset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!