獲取當前時間的前3天

2021-10-01 22:03:41 字數 856 閱讀 4072

根據當前時間獲取前3的時間(根據情況而定)

1.建立日曆類

calendar ca = calendar.getinstance(

)

2.設定當前時間

ca.settime(new date(

));

3.設定日期物件 ,並格式轉換 (根據自己需求轉換)

******dateformat df

= new ******dateformat(

"yyyy-mm-dd hh:mm:ss");

string endtime = df.format(ca.gettime(

));

4.自己的dto物件設定開始(當前)時間

ordershopdto.setendtime(endtime)

;

5.設定當前時間的前3天時間(需要獲取幾天就減幾天哦 !兄弟)

ca.add(calendar.date, -3)

;

6.再次獲取時間 就是當前時間的前3天時間

string begintime = df.format(ca.gettime(

));

7.最後再設定自己的dto物件中的結束(最終)時間

ordershopdto.setbegintime(begintime)

;

這樣就得到兩個時間哦 乙個是當前時間 乙個是3天前的時間哦 馬飛 哈哈哈 本人菜鳥程式猿 不足的地方還請大家指點哈

js獲取當前時間和7天前的時間

如果想要實現的完美些,當時間不滿10的時候 新增 0 由 1,2,3 變為 01,02,03 格式更統一,可新增三元表示式進行優化處理,如下 var day data.getdate 10 0 data.getdate data.getdate 年月日時分秒 都可替換為 如上的例子 獲取各種型別當前...

獲取當前時間

獲取日期 時間 datetime.now.tostring 2008 9 4 20 02 10 datetime.now.tolocaltime tostring 2008 9 4 20 12 12 獲取日期 datetime.now.tolongdatestring tostring 2008年9...

獲取當前時間

直接上可以執行的 檔案 獲取當前時間.cpp 方案 time 優點 僅使用c標準庫 缺點 只能精確到秒級 include time.h include stdio.h int main void 方案二getlocaltime 優點 能精確到毫秒級 缺點 使用了windows api include...