Java Calendar always shows the same time

后端 未结 5 1851
天命终不由人
天命终不由人 2020-12-07 05:05

Below is my code.

public class TestCalendar {

public static void main(String[] args){
    int unique_id = Integer.parseInt(\"\" + Calendar.HOUR + Calendar.M         


        
5条回答
  •  醉话见心
    2020-12-07 05:35

    Calendar.HOUR (or MINUTE, SECOND) is just an indicator that indicates which field we want to extract from the Calendar instance, not the value, i.e. we want to 'extract HOUR from the calendar object' like below:

    Calendar c = Calendar.getInstance();
    
    int hour = c.get(Calendar.HOUR_OF_DAY); // in 24-hours,
                                            // or c.get(Calendar.HOUR) in 12-hours.
    int minute = c.get(Calendar.MINUTE);
    int second = c.get(Calendar.SECOND);
    
    int weekday = c.get(Calendar.DAY_OF_WEEK);
    int weekOfYear = c.get(Calendar.WEEK_OF_YEAR);
    

提交回复
热议问题