本文介紹了Java日歷獲取當前日期,不帶小時、分鐘、秒和毫秒,以毫秒為單位的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時送ChatGPT賬號..
我想以毫秒為單位獲取當前日期,只有年、月和日期.但是當我使用這段代碼時:
I would like to get the current date in milliseconds with only year, month and date. But when I use this code:
Calendar cal = Calendar.getInstance();
cal.clear(Calendar.HOUR);
cal.clear(Calendar.MINUTE);
cal.clear(Calendar.SECOND);
cal.clear(Calendar.MILLISECOND);
currentDate = cal.getTimeInMillis();
我仍然以毫秒為單位獲得時間.我該如何解決這個問題?
I still get the time in milliseconds with the hour. How can I fix this?
推薦答案
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
currentDate = cal.getTimeInMillis();
請注意日歷的時區(qū).
這篇關(guān)于Java日歷獲取當前日期,不帶小時、分鐘、秒和毫秒,以毫秒為單位的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!