Calendar Class problems

前端 未结 6 700
梦谈多话
梦谈多话 2021-01-24 02:32

I am having problems with the Calendar Class.

Calendar cal = Calendar.getInstance ();

int iYear  = cal.get (Calendar.YEAR);         // get the curr         


        
6条回答
  •  逝去的感伤
    2021-01-24 03:03

    Let try this simple program:

    import java.util.Calendar;
    class CalendarExample {
    public static void main(String args[]) {
    
    Calendar calendar = Calendar.getInstance();
    System.out.println("Current Date : " + calendar.get(Calendar.DATE));
    System.out.println("Current Month : " + calendar.get(Calendar.MONTH));
    System.out.println("Current Year : " + calendar.get(Calendar.YEAR));
    System.out.print("Current Time : ");
    System.out.print(calendar.get(Calendar.HOUR) + ":");
    System.out.print(calendar.get(Calendar.MINUTE) + ":");
    System.out.print(calendar.get(Calendar.SECOND));
    }
    }
    

    You get the o/p:

    Current Date : 28
    Current Month : 1
    Current Year : 2014
    Current Time : 11:18:3
    

提交回复
热议问题