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

日歷的日期對象 [Java]

Date object to Calendar [Java](日歷的日期對象 [Java])
本文介紹了日歷的日期對象 [Java]的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有一堂課電影其中我有一個開始日期、一個持續時間和一個停止日期.開始和停止日期是日期對象(私有日期 startDate ...)(這是一個任務,所以我不能改變它)現在我想通過將持續時間(以分鐘為單位)添加到 startDate 來自動計算 stopDate.

I have a class Movie in it i have a start Date, a duration and a stop Date. Start and stop Date are Date Objects (private Date startDate ...) (It's an assignment so i cant change that) now I want to automatically calculate the stopDate by adding the duration (in min) to the startDate.

據我所知,不推薦使用 Date 的時間操縱功能,因此這是不好的做法,但另一方面,我看不到將 Date 對象轉換為日歷對象以操縱時間并將其重新轉換為 Date 對象的方法.有辦法嗎?如果有什么是最佳做法

By my knowledge working with the time manipulating functions of Date is deprecated hence bad practice but on the other side i see no way to convert the Date object to a calendar object in order to manipulate the time and reconvert it to a Date object. Is there a way? And if there is what would be best practice

推薦答案

你可以做的是創建一個 GregorianCalendar 的實例,然后將 Date 設置為開始時間:

What you could do is creating an instance of a GregorianCalendar and then set the Date as a start time:

Date date;
Calendar myCal = new GregorianCalendar();
myCal.setTime(date);

但是,另一種方法是根本不使用 Date.您可以使用這樣的方法:

However, another approach is to not use Date at all. You could use an approach like this:

private Calendar startTime;
private long duration;
private long startNanos;   //Nano-second precision, could be less precise
...
this.startTime = Calendar.getInstance();
this.duration = 0;
this.startNanos = System.nanoTime();

public void setEndTime() {
        this.duration = System.nanoTime() - this.startNanos;
}

public Calendar getStartTime() {
        return this.startTime;
}

public long getDuration() {
        return this.duration;
}

通過這種方式,您可以訪問開始時間并獲取從開始到停止的持續時間.當然,精度取決于您.

In this way you can access both the start time and get the duration from start to stop. The precision is up to you of course.

這篇關于日歷的日期對象 [Java]的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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:獲取當前星期幾的值)
主站蜘蛛池模板: 男女激情网 | 日韩在线成人 | 在线视频成人 | 91精品国产一区二区三区动漫 | 一级视频在线免费观看 | 国产精品久久久久久久午夜片 | 国产欧美日韩综合精品一区二区 | 一片毛片| 国产精品一区二区不卡 | 欧美一级在线观看 | 欧美一级二级在线观看 | 欧美一区二区在线观看 | 日韩在线免费视频 | 亚洲国产精品一区二区第一页 | 99在线免费观看视频 | 成人永久免费视频 | 中文字幕在线观看一区二区 | 日韩精品久久久 | 91久操网 | 国产乱码精品一品二品 | 99日韩 | 免费的网站www | 在线免费观看成年人视频 | 精品视频999| 久久久精品影院 | 国产97视频在线观看 | 国产精品国产精品国产专区不卡 | 日本三级电影在线观看视频 | 久久人人网 | 国产高清视频在线观看 | 日韩中文一区 | 久草新在线 | 欧美色综合 | 国产精品久久久久无码av | 国产在线精品一区二区三区 | 国产精品久久久久久久久久久久久 | 亚洲精品一区中文字幕乱码 | 欧美日日 | 国产精品久久久久久久久久三级 | 理伦毛片 | 国产精品亚洲欧美日韩一区在线 |