Java Calendar always shows the same time

后端 未结 5 1849
天命终不由人
天命终不由人 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:48

    For those who are still having some problems with this, like I did, especially when you want to print multiple times you may need to to use new like follows:

    System.out.println(""+new GregorianCalendar().get(Calendar.HOUR_OF_DAY)+":"+new GregorianCalendar().get(Calendar.MINUTE)+":"+new GregorianCalendar().get(Calendar.SECOND)+":"+new GregorianCalendar().get(Calendar.MILLISECOND));
    

提交回复
热议问题