Getting Year, Month and Date in Android

前端 未结 9 1932
走了就别回头了
走了就别回头了 2021-02-06 21:04

I am trying to get today\'s Year, Month and Date using following code;

Calendar calendar = Calendar.getInstance();

int thisYear = calendar.get(Calendar.YEAR);
L         


        
相关标签:
9条回答
  • 2021-02-06 21:54
    Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
    calendar.get(Calendar.YEAR)
    
    0 讨论(0)
  • 2021-02-06 21:57

    This gives the time and date of your android system so first check it.

    0 讨论(0)
  • 2021-02-06 21:58

    Try to use:

    Date dt = new Date(); 
    dt.getYear(); 
    dt.getMonth(); 
    dt.getDay();
    

    and see if you get the same result. If so, your system date is probably out of sync. Check the Date class documentation for more details:

    0 讨论(0)
提交回复
热议问题