如何从 UTC 日期格式获取正确的时区(服务器时区)?
作为以下链接的后续内容。
如何使用 javascript 或 jquery 将此日期类型 2010-06-24T00:00:00Z 格式化为 sun,24/06/10 7.15 pm (CDT)
我正在将 utc 日期格式转换为简单日期格式:
2010-06-24T00:00:00Z 到 sun,24/06/10 7.15 pm (CDT)(转换时间)
但是有没有办法识别有效时区,因为上述转换始终检测基于时区在客户端机器上。还是我们无法检测到 UTC 的有效时区?
As follow up of the below link.
I'm converting the utc date format to simple date format:
2010-06-24T00:00:00Z to sun,24/06/10 7.15 p.m (CDT) (converted time)
But is there a way to identify the valid timezone, as the above conversion always detects the time zone based on client machine. Or is it that we can't detect the valid time zone from UTC?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
UTC 没有时区,它是“通用的”,因为无论你在哪里,它总是相同的。时区信息必须由观察者确定。
UTC has no time zone, it is "universal" because it is always the same no matter where you are. Time zone information has to be determined by the observer.
您没有定义“有效时区”的含义 - 您的意思是本地时区吗? (毕竟 UTC 是一个完全有效的时区,或者至少如果您位于西欧时区且不是英国夏令时间的话……)
如果您有 UTC 日期并且想将其转换为日期在当地时区,这很简单:
You didn't define what you mean by "valid timezone" -- do you mean local timezone? (UTC is a perfectly valid timezone, after all--or at least it is if you're in the Western European Time Zone and it's not British Summer Time…)
If you have a UTC date and you want to turn it into a date in the local timezone, that's straightforward:
您可以在 C# 中使用以下代码通过传递时区值来获取日期(例如:+08:00:00)
You can use below code in C# to get the date by passing the timezone value (e.g.: +08:00:00)