In other words, I want functionality that provides Joda-Time:
today = today.withTime(0, 0, 0, 0);
but without Joda-Time, only with java.util.Date.
Methods such as .setHours() and etc. are deprecated. Is there are more correct way?
Insert a static date or time into an Excel cell On a worksheet, select the cell into which you want to insert the current date or time. Do one of the following: To insert the current date, press Ctrl+; (semi-colon).
today() The today() method of date class under DateTime module returns a date object which contains the value of Today's date. Returns: Return the current local date.
In JavaScript, we can easily get the current date or time by using the new Date() object. By default, it uses our browser's time zone and displays the date as a full text string, such as "Fri Jun 17 2022 10:54:59 GMT+0100 (British Summer Time)" that contains the current date, time, and time zone.
Date today = new Date(); today.setHours(0); //same for minutes and seconds
Since the methods are deprecated, you can do this with Calendar
:
Calendar today = Calendar.getInstance(); today.set(Calendar.HOUR_OF_DAY, 0); // same for minutes and seconds
And if you need a Date
object in the end, simply call today.getTime()
Date today = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH);
DateUtils from Apache Commons-Lang. Watch out for time zone!
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