久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

基于Java中的UTC偏移獲取時區快捷方式

Get timezone shortcut based on UTC offset in Java(基于Java中的UTC偏移獲取時區快捷方式)
本文介紹了基于Java中的UTC偏移獲取時區快捷方式的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我想根據 UTC 偏移量獲取 EST(東部標準)、PST(太平洋)等時區快捷方式.我意識到這不是一個簡單的問題,基于特定偏移量的位置可能不止一個,但這沒關系.

I want to get the timezone shortcut like EST (for eastern standard), PST (pacific), and so on based on the UTC offset. I realize it's not a simple problem and there can be more than one location based on a particular offset, but that's okay.

我正在嘗試使用 Util Calendar 對象來獲取它,但我似乎沒有得到字符串,而只是得到了偏移量.

I'm trying to get it using Util Calendar object but I don't seem to get a string but rather just the offset.

public String foo(int offset)
{
....
return TimeZoneShortcut;
} 

提前致謝.

推薦答案

user2580516的回答是正確的.我可以再補充一點.

The answer by user2580516 is correct. I can add a bit more.

三個字母的時區 ID 既不標準化也不唯一.避開他們.

The three-letter time zone IDs are neither standardized nor unique. Avoid them.

例如,IST 用于表示印度標準時間 愛爾蘭標準時間.有很多這樣的碰撞.

For example, IST is used to mean India Standard Time or Irish Standard Time. There are many such collisions.

不要使用 3 個字母的代碼,而是使用正確的時區名稱.示例:歐洲/巴黎"、美國/蒙特利爾"和亞洲/加爾各答".

Instead of 3-letter codes, use proper time zone names. Examples: "Europe/Paris", "America/Montreal", and "Asia/Kolkata".

似乎沒有時區名稱的官方標準.這讓我感到驚訝;希望我錯了,有人可以填寫.無論如何,常用??的列表來自 tz 數據庫(以前稱為 Olson 數據庫),如 在此維基百科頁面中列出.

There does not seem to be an official standard for time zone names. That surprises me; hopefully I'm wrong and someone can fill me in. At any rate, a commonly used list is take from the tz database (formerly known as the Olson database), as listed in this Wikipedia page.

優秀的日期時間庫,Joda-Time,有生成方法當前已知時區名稱的列表.

The excellent date-time library, Joda-Time, has a method to generate a list of its currently known time zone names.

時區名稱會隨著時間的推移而變化,一些會被添加,它們的規則也會發生變化.這一切都是由政客和官僚決定的,所以改變是最后一刻的,并不總是明智的.所以你應該注意保持你的日期時間庫是最新的,或者至少更新它包含的時區數據庫.

The time zone names change over time, some are added, and their rules change too. All that is determined by politicians and bureaucrats, so changes are last-minute and not always sensible. So you should take care to keep your date-time library up-to-date, or at least update its contained time zone database.

時區不僅僅是與 UTC/GMT.時區還包含 夏令時 (DST) 和其他異常情況的規則集.

A time zone is more than just an numerical offset from UTC/GMT. A time zone also contains the set of rules for Daylight Saving Time (DST) and other anomalies.

因此,您無法從偏移量推斷時區.你可以猜測,但你不能確定.

So you cannot infer a time zone from an offset. You can guess, but you cannot be sure.

例如取+01:00的偏移量.那是歐洲/巴黎"還是非洲/拉各斯"?兩者都有 UTC 前一小時的偏移量.那么你使用哪個重要嗎?是的……法國遵守夏令時,但尼日利亞沒有.分配錯誤的時區意味著您的日期時間計算將是錯誤的.

For example, take the offset of +01:00. Is that "Europe/Paris" or "Africa/Lagos"? Both have an offset of one hour ahead of UTC. So does it matter which you use? Yes… France observes Daylight Saving Time but Nigeria does not. Assigning the wrong time zone means your date-time calculations will be wrong.

另一個轉折……也許那個 +01:00 是在夏季的倫敦錄制的.在夏季,倫敦遵守 DST 并將時鐘提前 1 小時.雖然標準時間是 +00:00(在 UTC/GMT 上),但 DST 將它們提前一小時.

Another twist… Perhaps that +01:00 was recorded in London during the summer time. In summer, London observes DST and moves its clocks 1 hour ahead. While standard time there is +00:00 (on UTC/GMT), DST moves them one hour ahead of that.

又一個轉折點……即使你說隨便挑一個",是哪一個?對于標準時間的+00:00,至少有2個三字母代碼(CETMET)和37個命名時區跨越兩大洲.

Yet another twist… Even if you say "just pick one", which one? For +00:00 in just standard time, there are at least 2 three-letter codes (CET and MET) and 37 named time zones crossing two continents.

也許您在想,我可以使用日期來確定 DST 是否生效".不,DST 在不同時區的不同日期開始和結束,共享相同的偏移量.此外,一些國家(時區)足夠明智,不會被 DST 愚弄.

Perhaps you are thinking, "I can use the date to figure out if DST was in effect". Nope, DST starts and ends on different dates in various time zones sharing the same offset. Furthermore, some countries (time zones) are sensible enough to not fool with DST.

因此,關于您的問題不是一個簡單的問題......但沒關系"是錯誤的.這不是問題,這是不可能的.就像這個問題,給定一個生日,確定一個人".您可以確定一個人或時區正確,但您無法確定哪個正確.

So regarding your question being "not a simple problem … but that's okay" is wrong. It's not a problem, it's impossible. Like the question, "Given a birthday, determine an individual person". You can determine that a person or time zone is not correct, but you cannot determine which is correct.

如果了解時區(其位置和規則)對您很重要,則必須記錄時區信息以及日期時間.例如,這可能意味著您的數據庫中有一個額外的字段.

If knowing the time zone (its locality and rules) is important to you, you must record the zone information along with the date-time. This may mean an extra field in your database for example.

Java 8 帶來了新的 java.time.8 包,靈感來自 Joda-Time,由 JSR 310.設計者已經意識到時區作為日期時間值的一部分的重要性.因此,他們的設計包括:

Java 8 brings a new java.time.8 package, inspired by Joda-Time, defined by JSR 310. The designers have come to realize the importance of the time zone as a part of a date-time value. As a result, their designs include:

  • 主要的日期時間類以Zoned"一詞開頭,以強調該類包含時區信息:ZonedDateTime
  • 他們在 ZonedDateTime 類上的 toString 實現擴展了 ISO 8601 通過在括號中附加時區名稱來格式化.而不是:
    2014-02-14T20:51:55.427-08:00
    它輸出
    2014-02-14T20:51:55.427-08:00[美國/洛杉磯]
  • The main date-time class starts with the word "Zoned" to stress that the class includes time zone info: ZonedDateTime
  • Their toString implementation on the ZonedDateTime class extends the ISO 8601 format by appending the name of the time zone in brackets. Instead of:
    2014-02-14T20:51:55.427-08:00
    it outputs
    2014-02-14T20:51:55.427-08:00[America/Los_Angeles]

這篇關于基于Java中的UTC偏移獲取時區快捷方式的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 黄色大片在线播放 | 极品销魂美女一区二区 | 免费黄色录像片 | 日本a视频 | 欧美精品一区二区三区蜜桃视频 | 蜜臀久久99精品久久久久野外 | 天天激情综合 | 精品二 | 日韩在线免费视频 | 国产99久久精品一区二区永久免费 | 国产精品日产欧美久久久久 | 国产精品国产精品 | 一区二区三区视频在线 | 久久尤物免费一区二区三区 | 日韩一区二区三区视频 | 精品久久精品 | 免费视频二区 | av在线黄| 黄色网址免费在线观看 | 欧美专区在线视频 | 亚洲欧美日本国产 | 日韩色图在线观看 | 国产91视频播放 | 国产精品视频yy9299一区 | 羞羞色在线观看 | 欧美中文字幕一区二区三区亚洲 | 中国人pornoxxx麻豆 | 久久精品国产久精国产 | 91精品久久久久久久久久 | av网站免费 | 久久国内精品 | 在线视频一区二区三区 | 视频在线一区二区 | 精品日韩| 欧美日韩一区精品 | 亚州精品成人 | 欧美一区二区三区视频在线观看 | 国产欧美日韩一区 | 激情三区 | 成人亚洲视频 | 国产精品一级 |