This is my existing code snippet:
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);
I just want to assign those attributes at once, something like:
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND, Calendar.MILLISECOND, 0);
I am not sure it is possible or not, because I am new to java. Please help me if there is other way around to achive this.
If possible, please give others solutions also. Objective is to set the given cal
object to 00:00:00.000
A.M.
Edit 1: I think this question was clear and understandable. Please consider upvoting as I couldn't ask anymore questions on stackoverflow.
The old Calendar class can be set by the current generation of java time classes:
// Current time classes:
LocalDate today = LocalDate.now();
// LocalDate today = LocalDate.of(2020, 2, 18);
LocalDateTime morning = today.atStartOfDay();
// Old classes:
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(morning.toEpochSecond()));