久久久久久久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精品在线 | 色婷婷精品 | 日日操操操 | 色偷偷人人澡人人爽人人模 | 久草高清视频 | 中文字幕一区二区三区乱码在线 | 国产精品亚洲精品日韩已方 | 激情综合五月 | 91欧美精品成人综合在线观看 | 国产aaaaav久久久一区二区 | 亚洲精品一区二区三区 | 成年免费大片黄在线观看一级 | 欧美综合一区 | 欧美美女爱爱视频 | 国产线视频精品免费观看视频 | 成人精品高清 | 亚洲精品9999 | 欧美日韩国产中文 | 亚洲一区在线免费观看 | 国产精品国产成人国产三级 | 青春草91| 国产成人福利在线观看 | 五月综合久久 | 中文字幕福利视频 | 欧美一区二区在线看 | 一区二区精品电影 | 国产精品高清一区二区三区 | 日韩三级电影一区二区 |