Getting Year, Month and Date in Android

前端 未结 9 1925
走了就别回头了
走了就别回头了 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条回答
  •  梦毁少年i
    2021-02-06 21:40

    The month starts from zero so you have to add 1 with the given month to show the month number we are familiar with.

    int thisMonth = calendar.get(Calendar.MONTH);
    Log.d(TAG, "@ thisMonth : " + (thisMonth+1));
    

    This will show you the current month starting with 1.

提交回复
热议问题