What is the point of calendar.setTimeInMillis (System.currentTimeMillis ()) immediately after creating the instance?

In many posts and even on Google ( here ) I saw this code:

// Set the alarm to start at approximately 2:00 p.m.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());

Therefore, I tested it in a standalone Java program (not for Android):

Calendar c = Calendar.getInstance();
System.out.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date(System.currentTimeMillis())));
System.out.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date(c.getTimeInMillis())));

Exit:

01:23:33.884
01:23:33.876

It works great without setting the time using setTimeInMillis explicitly.

What is the point of calendar.setTimeInMillis (System.currentTimeMillis ())? This is a mistake, especially. in Android programming so as not to set it that way?

+4
source share

Source: https://habr.com/ru/post/1614898/


All Articles