獲取時間間隔內每個時間點對應的時間

2022-09-09 08:15:14 字數 1157 閱讀 2833

測試:

按1分鐘分割

@test

public

void

mytest()

結果:

按一天分割

@test

public

void

mytest()

結果:

邏輯**:

/**

* 迴圈條件為開始時間小於截止時間,若滿足條件,開始時間就加上時間間隔

* @param

starttime 開始時間

* @param

endtime 截止時間

* @param

format 返回資料的時間格式

* @param

unit 按分鐘、天劃分(calendar.minute,calendar.day_of_month,..........)

* @param

interval 時間間隔(1,2,3,......)

* @return

*/public mapgetquerytime(string starttime, string endtime, string format, int unit, int

interval)

timemap.put(starttime,starttime);

} catch

(exception e)

return

timemap;

}private string getdatetimebyinterval(string readingtime,int interval,int

unit,string format)

catch

(parseexception e)

return

new******dateformat(format).format(calendar.gettime());

}

獲取時間間隔 不受系統時間影響

windows平台下 include dword dwtimecout1 gettickcount 作業系統啟動到現在持續的毫秒數 sleep 10000 在sleep的這十秒內如果修改系統時間,不影響時間間隔 dword dwtimecout2 gettickcount int ninterval...

JQ獲取當前時間到目標時間的間隔

今天開發的時候,有乙個小需求是需要把某個值存如cookie,過期時間為第二天的0點。我們框架的cookie寫入是以小時為單位傳入的。那麼我就想寫乙個方法計算當前時間到第二天0點的時間間隔。function gettimeinterval 到這為止,我的需求就解決了。這裡返回的單位是小時,如果需要返回...

python 獲取時間間隔時間戳日期

在現實專案中經常會用到時間戳輪,因為有時候資料是按小時儲存,按小時取出某一天的資料,因此需要輪詢去取時間 在python中 可以這樣 begintime int time.mktime time.strptime 20181023 y m d endtime begintime 86400 for ...