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. getInstance(). getTime() : Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch(January 1, 1970 00:00:00.000 GMT (Gregorian).)
System. out. printf("%d-%02d-%02d %02d:%02d:%02d. %03d", year, month, day, hour, minute, second, millis);
JavaScript - Date getMilliseconds() Method Javascript date getMilliseconds() method returns the milliseconds in the specified date according to local time. The value returned by getMilliseconds() is a number between 0 and 999.
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();
Be carefull on the timezone of your Calendar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With