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

從紀元以來的天數獲取 java.util.Calendar

Get java.util.Calendar from days since epoch(從紀元以來的天數獲取 java.util.Calendar)
本文介紹了從紀元以來的天數獲取 java.util.Calendar的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有一個變量,其中包含 紀元參考日期 code>1970-01-01 某個日期.

I have a variable containing the days since the epoch reference date of 1970-01-01 for a certain date.

有人知道如何將此變量轉換為 java.util.Calendar?

Does someone know the way to convert this variable to a java.util.Calendar?

推薦答案

以下應該可以:

Calendar c = new GregorianCalendar();
c.setTime(new Date(0));

c.add(Calendar.DAY_OF_YEAR, 1000);

System.err.println(c.getTime());

<小時>

關于時區的說明:


A note regarding time zones:

使用運行程序的系統的默認時區創建一個新的 GregorianCalendar 實例.由于 Epoch 與 UTC(Java 中的 GMT)相關,因此必須小心處理任何不同于 UTC 的時區.下面的程序說明了這個問題:

A new GregorianCalendar instance is created using the default time zone of the system the program is running on. Since Epoch is relative to UTC (GMT in Java) any time zone different from UTC must be handled with care. The following program illustrates the problem:

TimeZone.setDefault(TimeZone.getTimeZone("GMT-1"));

Calendar c = new GregorianCalendar();
c.setTimeInMillis(0);

System.err.println(c.getTime());
System.err.println(c.get(Calendar.DAY_OF_YEAR));

c.add(Calendar.DAY_OF_YEAR, 1);
System.err.println(c.getTime());
System.err.println(c.get(Calendar.DAY_OF_YEAR));

打印出來

Wed Dec 31 23:00:00 GMT-01:00 1969
365
Thu Jan 01 23:00:00 GMT-01:00 1970
1

這表明僅使用 e.g. 是不夠的.c.get(Calendar.DAY_OF_YEAR).在這種情況下,必須始終考慮到它是一天中的什么時間.這可以通過在創建 GregorianCalendar 時顯式使用 GMT 來避免:new GregorianCalendar(TimeZone.getTimeZone("GMT")).如果日歷是這樣創建的,則輸出為:

This demonstrates that it is not enough to use e.g. c.get(Calendar.DAY_OF_YEAR). In this case one must always take into account what time of day it is. This can be avoided by using GMT explicitly when creating the GregorianCalendar: new GregorianCalendar(TimeZone.getTimeZone("GMT")). If the calendar is created such, the output is:

Wed Dec 31 23:00:00 GMT-01:00 1969
1
Thu Jan 01 23:00:00 GMT-01:00 1970
2

現在日歷返回有用的值.c.getTime() 返回的 Date 仍然關閉"的原因是 toString() 方法使用了默認的 TimeZone 來構建字符串.在頂部,我們將其設置為 GMT-1,因此一切正常.

Now the calendar returns useful values. The reason why the Date returned by c.getTime() is still "off" is that the toString() method uses the default TimeZone to build the string. At the top we set this to GMT-1 so everything is normal.

這篇關于從紀元以來的天數獲取 java.util.Calendar的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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区| 久久中文字幕av | 97成人免费| 日韩中文一区二区三区 | 国产成人精品一区二三区在线观看 | 一区二区三区在线观看视频 | 7799精品视频天天看 | 国产真实精品久久二三区 | 欧美在线视频网 | 成人免费视屏 | 91精品国产91久久久久久最新 | 亚洲一区国产 | 久久久精彩视频 | 天天射天天操天天干 | 亚洲精品视频网站在线观看 | 人人九九 | 亚洲精品一区二区三区中文字幕 | 成年人网站在线观看视频 | 久久国产高清 | 91精品一区二区 | 成人av免费网站 | 国产无套一区二区三区久久 | 四虎免费视频 | 中文字幕成人在线 | a视频在线 | 日韩精品视频一区二区三区 | 免费观看av| 午夜影院在线视频 | 成人精品鲁一区一区二区 | 日本精品在线观看 | 黄色av网站在线免费观看 | a久久| 成人一级毛片 | 天天夜夜操 | 美女视频网站久久 | 成人影院在线观看 | 久久精品国产久精国产 |