久久久久久久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:獲取當前星期幾的值)
主站蜘蛛池模板: 欧美精产国品一二三区 | 一区二区三区国产精品 | 亚洲国产免费 | 久久精品一 | 久久精品亚洲 | yiren22综合网成人 | 琪琪午夜伦伦电影福利片 | 欧美激情在线精品一区二区三区 | 一级毛片视频 | 一区二区三区四区视频 | 精品一区二区在线观看 | 午夜精品一区二区三区在线视频 | 欧美激情a∨在线视频播放 成人免费共享视频 | 欧美一a| 国产精品婷婷 | 韩日一区二区三区 | 欧美日韩电影免费观看 | 精品毛片在线观看 | 欧美三区 | 99tv| 97精品超碰一区二区三区 | 国产精品成人一区二区三区 | 国产一区二区精品在线 | 久久成人激情 | 亚洲综合一区二区三区 | 国产一区在线免费 | 国产一区黄色 | 中文字幕日韩欧美一区二区三区 | 成人三区| 欧美国产一区二区 | 亚洲精品区 | 亚洲精品自在在线观看 | 午夜影院视频在线观看 | 91精品国产日韩91久久久久久 | 国产视频久久 | 久热久 | 99久久99久久精品国产片果冰 | 99热在线播放 | 欧美在线观看一区 | 国产精品一区二区三级 | 在线一区 |