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

在 Java 中使用各種日歷時區(不使用 Joda Time)

Working with various Calendar TimeZone in Java (without using Joda Time)(在 Java 中使用各種日歷時區(不使用 Joda Time))
本文介紹了在 Java 中使用各種日歷時區(不使用 Joda Time)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在尋找一種方法來根據用戶輸入獲取不同時區的當前時間.我知道我可以使用 Joda Time!但這是唯一的方法嗎?

I was looking for a way to get current time in various timezones based on an user input. I know I could use Joda Time! but is that the only way?

在 Java 中沒有這樣做的選項嗎?我嘗試了以下代碼,它為所有 3 個系統輸出提供了相同的輸出.

Isn't there an option in Java for doing this? I tried the following code which gives the same output for all 3 sysouts.

Calendar pst = Calendar.getInstance(TimeZone.getTimeZone("PST"));
System.out.println("PST " + pst.getTime());
Calendar ist = Calendar.getInstance(TimeZone.getTimeZone("Asia/Calcutta"));
System.out.println("IST " + ist.getTime());
Calendar utc = Calendar.getInstance(TimeZone.getTimeZone("Etc/UTC"));
System.out.println("UCT " + utc.getTime());

我在這里缺少什么來獲取其他時區的當前時間?

What am I missing here to get current time in other timezones?

推薦答案

是的,這將在每種情況下(或相隔毫秒)顯示相同的值,因為三個日歷都引用相同的即時 (盡管有執行時間),這就是 java.util.Date 所代表的全部內容.這是 Calendar.getTime() 的結果.

Yes, that would show the same value in every case (or milliseconds apart) because the three calendars all refer to the same instant in time (execution time notwithstanding) and that's all that a java.util.Date represents. That's the result of Calendar.getTime().

但是,Calendar 本身確實知道時區,這將在您使用 Calendar.get 等時反映出來.它將在您使用 SimpleDateFormat 時使用,您可以在其中指定特定時區.

However, the Calendar itself does know about time zones, and that will be reflected when you use Calendar.get etc. It will also be used when you use a SimpleDateFormat, where you can specify a particular time zone.

// Specify whatever format you want - bear in mind different locales etc
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
format.setTimeZone(calendar.getTimeZone());
String text = format.format(calendar.getTime());

目前尚不清楚您要做什么,但基本上您需要知道哪些類型是時區感知的,哪些不是.了解 java.util.Date 沒有格式、日歷系統或時區非常重要:它只是自 Unix 以來的毫秒數紀元.

It's not clear exactly what you're trying to do, but basically you need to be aware of which types are time zone aware, and which aren't. It's really important to understand that a java.util.Date doesn't have a format, a calendar system or a time zone: it's just the number of milliseconds since the Unix epoch.

這篇關于在 Java 中使用各種日歷時區(不使用 Joda Time)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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:獲取當前星期幾的值)
主站蜘蛛池模板: 免费观看一级黄色录像 | 欧美在线一区二区三区 | 蜜臀网| 国产婷婷精品av在线 | 香蕉超碰 | 欧美一区在线视频 | 91久久久久久| 国产福利91精品 | 亚洲电影专区 | 一区二区三区在线观看视频 | 国产一区二区影院 | 亚洲一区二区三区免费观看 | 国产一级片久久久 | 精品av天堂毛片久久久借种 | 国产婷婷色一区二区三区 | h视频在线观看免费 | 在线观看免费av片 | 亚洲成av人片在线观看无码 | 亚洲精彩视频 | 久久久免费电影 | 成人国产精品久久久 | 日本电影网站 | 免费三级av | 午夜精品久久久 | 成人影院一区二区三区 | 亚洲一区电影 | 成人精品一区二区户外勾搭野战 | 久久久精品一区 | 五月婷亚洲 | 91视频电影| 四虎在线观看 | 欧美精品在线免费观看 | 国产精品久久久久久吹潮 | 午夜电影网 | 91在线成人 | 国产欧美一区二区在线观看 | 午夜免费福利电影 | 九色91视频 | 在线播放一区二区三区 | 精品久久久久久久人人人人传媒 | 国产精品18毛片一区二区 |