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

獲取自 Java 中的 Epoch 以來的天數、周數和月數

Get the number of days, weeks, and months, since Epoch in Java(獲取自 Java 中的 Epoch 以來的天數、周數和月數)
本文介紹了獲取自 Java 中的 Epoch 以來的天數、周數和月數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我試圖在 Java 中獲取自 Epoch 以來的天數、周數、月數.

I'm trying to get the number of days, weeks, months since Epoch in Java.

Java Calendar 類提供了諸如 calendar.get(GregorianCalendar.DAY_OF_YEAR) 或 Calendar.get(GregorianCalendar.WEEK_OF_YEAR) 之類的東西,這是一個好的開始,但它并不能完全滿足我的需要.

The Java Calendar class offers things like calendar.get(GregorianCalendar.DAY_OF_YEAR), or Calendar.get(GregorianCalendar.WEEK_OF_YEAR), which is a good start but it doesn't do exactly what I need.

在 Java 中是否有一種優雅的方法可以做到這一點?

Is there an elegant way to do this in Java?

推薦答案

你可以使用 Joda Timelibrary 很容易做到這一點 - 除了使用標準 Java Date 和 Calendar 類之外,我將它用于與時間相關的任何事情.看看下面使用該庫的示例:

You can use the Joda Time library to do this pretty easily - I use it for anything time related other than using the standard Java Date and Calendar classes. Take a look at the example below using the library:

MutableDateTime epoch = new MutableDateTime();
epoch.setDate(0); //Set to Epoch time
DateTime now = new DateTime();

Days days = Days.daysBetween(epoch, now);
Weeks weeks = Weeks.weeksBetween(epoch, now);
Months months = Months.monthsBetween(epoch, now);

System.out.println("Days Since Epoch: " + days.getDays());
System.out.println("Weeks Since Epoch: " + weeks.getWeeks());
System.out.println("Months Since Epoch: " + months.getMonths());

當我運行它時,我得到以下輸出:

When I run this I get the following output:

Days Since Epoch: 15122
Weeks Since Epoch: 2160
Months Since Epoch: 496

這篇關于獲取自 Java 中的 Epoch 以來的天數、周數和月數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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影院在线观看 | 99久久精品国产一区二区三区 | 亚洲一区二区精品视频 | 男人的天堂久久 | 精品久久久久久久久久久 | 户外露出一区二区三区 | 国产精品视频在线观看 | 亚洲欧美视频一区 | 日韩欧美国产综合 | 日韩精品免费在线观看 | 亚洲精品无 | 亚洲 精品 综合 精品 自拍 | 中文字幕在线剧情 | 亚洲三级视频 | 宅男伊人 | 91麻豆精品国产91久久久更新资源速度超快 | 欧美在线视频网 | 欧美日韩在线免费 | 亚州综合在线 | 啪啪免费网站 | 亚洲二区在线 | 国产精品一区二区久久 | 日本久久精 | 狠狠色综合网站久久久久久久 | 亚洲精品成人网 | 免费黄篇 | 色在线免费 | 91精品国产一区二区三区动漫 | 夜夜爽99久久国产综合精品女不卡 |