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

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

Working with various Calendar TimeZone in Java (without using Joda Time)(在 Java 中使用各種日歷時(shí)區(qū)(不使用 Joda Time))
本文介紹了在 Java 中使用各種日歷時(shí)區(qū)(不使用 Joda Time)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

我正在尋找一種方法來(lái)根據(jù)用戶(hù)輸入獲取不同時(shí)區(qū)的當(dāng)前時(shí)間.我知道我可以使用 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 中沒(méi)有這樣做的選項(xiàng)嗎?我嘗試了以下代碼,它為所有 3 個(gè)系統(tǒng)輸出提供了相同的輸出.

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());

我在這里缺少什么來(lái)獲取其他時(shí)區(qū)的當(dāng)前時(shí)間?

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

推薦答案

是的,這將在每種情況下(或相隔毫秒)顯示相同的值,因?yàn)槿齻€(gè)日歷都引用相同的即時(shí) (盡管有執(zhí)行時(shí)間),這就是 java.util.Date 所代表的全部?jī)?nèi)容.這是 Calendar.getTime() 的結(jié)果.

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 本身確實(shí)知道時(shí)區(qū),這將在您使用 Calendar.get 等時(shí)反映出來(lái).它將在您使用 SimpleDateFormat 時(shí)使用,您可以在其中指定特定時(shí)區(qū).

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());

目前尚不清楚您要做什么,但基本上您需要知道哪些類(lèi)型是時(shí)區(qū)感知的,哪些不是.了解 java.util.Date 沒(méi)有格式、日歷系統(tǒng)或時(shí)區(qū)非常重要:它只是自 Unix 以來(lái)的毫秒數(shù)紀(jì)元.

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.

這篇關(guān)于在 Java 中使用各種日歷時(shí)區(qū)(不使用 Joda Time)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時(shí)間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
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 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 天天干国产 | 免费视频成人国产精品网站 | 国产中文字幕网 | 国产一区精品 | 成人网址在线观看 | 国产一区二区三区在线免费 | 国产视频久久 | 国产欧美一区二区精品忘忧草 | 亚洲一区二区三区免费在线观看 | 精品免费国产一区二区三区 | 免费看a | 一级欧美一级日韩片免费观看 | 五月花丁香婷婷 | 亚洲网址在线观看 | 欧美日韩亚洲一区 | 欧美激情精品久久久久久变态 | 日本在线视频一区二区 | 污片在线免费观看 | 国产高清在线 | 欧美天堂在线观看 | 精品一区二区电影 | 国产在线观看不卡一区二区三区 | 国产在线一区二区三区 | 亚洲经典一区 | 久久精品99 | 99精品免费视频 | 91亚洲精 | 午夜精品久久久 | 日本成年免费网站 | 精品伦精品一区二区三区视频 | 国产精品精品视频一区二区三区 | ririsao久久精品一区 | 三级视频网站 | 97人人澡人人爽91综合色 | 久久久性色精品国产免费观看 | 国产成人一区二区三区久久久 | 九九热在线视频观看这里只有精品 | 精品久久影院 | com.色.www在线观看 | 国产精品欧美一区二区三区不卡 | 成人av在线播放 |