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

將 1 周添加到日期,首選哪種方式?

Add 1 Week to a Date, which way is preferred?(將 1 周添加到日期,首選哪種方式?)
本文介紹了將 1 周添加到日期,首選哪種方式?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

我正在審查一些工作中的代碼,并發(fā)現(xiàn)代碼處理將當(dāng)前時間增加 1 周的方式不一致,我想知道是否有任何理由真正應(yīng)該優(yōu)先于另一個:

I am reviewing some code at work and came across an inconsistency in how the code handles adding 1 week to the current time and was wondering if there was any reason why one should really be preferred over the other:

第一個是實用方法:

public static Date addDaysToDate(final Date date, int noOfDays) {
    Date newDate = new Date(date.getTime());

    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(newDate);
    calendar.add(Calendar.DATE, noOfDays);
    newDate.setTime(calendar.getTime().getTime());

    return newDate;
}

第二個使用簡單的毫秒算術(shù):

And the second used simple millisecond arithmetic:

long theFuture = System.currentTimeMillis() + (86400 * 7 * 1000);
Date nextWeek = new Date(theFuture);

第二種方法顯然使用幻數(shù)"來定義一周,但這可以移動到一個常數(shù) MILLISECONDS_IN_ONE_WEEK = 86400 * 7 * 1000 那么除此之外,還有什么原因這些方法中的哪一種應(yīng)該優(yōu)于其他方法?

The second method obviously uses 'magic numbers' to define a week, but this could be moved to a constant MILLISECONDS_IN_ONE_WEEK = 86400 * 7 * 1000 So other than that, is there any reasons why one of these methods should be preferred over the other?

基本上我想更改代碼以使其始終保持一致,但我不完全確定要刪除哪一個.因此,任何一種或另一種方式的論點都是有用的.

Basically I want to change the code to be consistent throughout, but I'm not entirely sure which one to remove. So any arguments one way or the other would be useful.

推薦答案

這兩種方法在夏令時邊界上的行為會有所不同.第一種方法將繼續(xù)返回一天中的同一時間,無論夏令時狀態(tài)如何.第二種方法將返回隨著夏令時開始和停止而在每個方向變化一小時的時間.

The two methods will behave differently on daylight savings boundaries. The first method will continue returning the same time of the day, regardless of daylight savings status. The second method will return times which vary an hour in each direction as daylight savings time starts and stops.

這篇關(guān)于將 1 周添加到日期,首選哪種方式?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
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 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 日韩1区| 国产精品久久九九 | 日韩一区二区三区在线看 | 精品久久久久久久 | 久久免费高清视频 | 夜夜骑综合 | 一级黄片一级毛片 | 国产精品国产精品国产专区不片 | 国产精品国产 | 高清免费在线 | 日韩av免费在线观看 | 欧美精品日韩 | 日韩成人在线播放 | 成在线人视频免费视频 | 久久久久久久一区二区三区 | 91香蕉视频在线观看 | 日韩伦理一区二区 | 少妇久久久 | 综合久久av | 日韩欧美精品一区 | 91精品久久久久久综合五月天 | 久久999| 久久精品一区二区视频 | 日韩精品一区二区三区视频播放 | 成人一区二区三区在线观看 | 日韩高清在线 | 欧美国产日韩在线观看成人 | 欧美精品一区二区在线观看 | 日韩有码一区二区三区 | 中文字幕免费视频 | 午夜一区二区三区在线观看 | 人人擦人人干 | 一级国产精品一级国产精品片 | 精品国产一区二区三区性色av | h视频在线免费 | 在线观看国产视频 | 免费看黄色视屏 | 日韩精品一区中文字幕 | 欧美a在线看 | 日韩美香港a一级毛片免费 国产综合av | 黄色大片免费看 |