久久久久久久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:獲取當前星期幾的值)
主站蜘蛛池模板: 99国产精品久久久久老师 | 国产精品日日做人人爱 | 精品国产欧美一区二区三区成人 | 中文字幕亚洲精品在线观看 | 国产一区二区在线免费观看 | 欧美日韩国产一区二区三区 | 亚洲欧美中文日韩在线v日本 | 丁香婷婷久久久综合精品国产 | 国产精品亚洲一区 | 韩日在线视频 | 美女福利网站 | 一区二区三区成人 | 一二三在线视频 | 99热在线观看精品 | 日本午夜精品 | 在线观看视频亚洲 | 亚洲视频中文 | 人成在线 | 国产精品久久久久久二区 | 亚洲精品乱码久久久久久黑人 | 伊人免费在线观看 | 亚洲综合一区二区三区 | 国产婷婷| 久久久久久久久久久一区二区 | 亚洲最大的黄色网址 | 日本成人中文字幕 | 久久天堂 | 成人h动漫精品一区二区器材 | 国产91久久久久久久免费 | 羞羞视频网站免费观看 | 日本免费一区二区三区 | 正在播放一区二区 | aaa在线| 毛片免费看 | 亚洲一区二区在线播放 | 操操操日日日 | 日本成人中文字幕在线观看 | 一区二区中文 | 精品一区二区不卡 | 亚洲精品一区二区三区中文字幕 | 国产欧美精品 |