猜测自定义日期的时区名称 [英] Guess timezone name for custom date

查看:97
本文介绍了猜测自定义日期的时区名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以获取浏览器时区名称:moment.tz.guess()

I know that I can get browser timezone name: moment.tz.guess()

如何猜测自定义日期的时区?例如moment("2020-12-30T14:17:40+11:00").tz.guess()吗?

How can I guess timezone for custom date? e.g. moment("2020-12-30T14:17:40+11:00").tz.guess() ?

推荐答案

您不能.有9个不同的位置区域全年使用+11:00,还有5个使用夏令时.

You can't. There are 9 different location-based zones that use +11:00 year round, and 5 more that use it for daylight saving time.

如果将日期和时间放入夏令时有效且标准时间不匹配的时区中,则可以消除一些误差.最好的办法是随机选择一个.

You might be able to eliminate a few if the date and time put it into a time zone where daylight time is not in effect and the standard time doesn't match, but from there, the best you could do would be to pick one at random.

请参见时区标签Wiki 中的时区!=偏移量".

See "time zone != offset" in the timezone tag wiki.

Moment-timezone可以猜测浏览器的时区,因为它可以查询 multiple 不同时间戳的偏移量,从而从算法上降低了可能性.即使到那时,通常也有数种可以匹配,因此最有可能被选中(基于人口统计数据).最后,这仍然是一个猜测.

Moment-timezone can guess the browser's time zone because it can query the offset for multiple different timestamps, algorithmically reducing the possibilities. Even then, there are often several that could match, and thus the most likely one is picked (based on population statistics). In the end, it's still a guess.

这篇关于猜测自定义日期的时区名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆