Java의 날짜 클래스(예제 포함)

Date 클래스는 밀리초 정밀도로 특정 순간을 나타냅니다. java.util 패키지의 Date 클래스는 Serialized Cloneable 및 Comparable 인터페이스를 구현합니다. Java로 날짜와 시간을 처리하기 위한 생성자와 메소드를 제공합니다. 생성자
    날짜() : 현재 날짜와 시간을 나타내는 날짜 객체를 생성합니다. 날짜(긴 밀리초) : 1970년 1월 1일 00:00:00 GMT 이후 지정된 밀리초 동안의 날짜 객체를 생성합니다. 날짜(int 연 int ​​월 int 날짜) 날짜(int 연도 int 월 int 날짜 int 시간 int min) 날짜(int 연도 int 월 int 날짜 int hrs int min int sec) 날짜(문자열 s) 메모 : The last 4 constructors of the Date class are Deprecated. Java
       // Java program to demonstrate constuctors of Date   import     java.util.*  ;   public     class   Main   {      public     static     void     main  (  String  []     args  )      {      Date     d1     =     new     Date  ();      System  .  out  .  println  (  'Current date is '     +     d1  );      Date     d2     =     new     Date  (  2323223232L  );      System  .  out  .  println  (  'Date represented is '  +     d2     );      }   }   
    Output:
    Current date is Tue Jul 12 18:35:37 IST 2016 Date represented is Wed Jan 28 02:50:23 IST 1970  
    중요한 방법
      부울 이후(날짜 날짜) : 현재 날짜가 주어진 날짜 이후인지 테스트합니다. 이전 부울(날짜 날짜) : 현재 날짜가 주어진 날짜 이전인지 테스트합니다. int CompareTo(날짜 날짜) : 현재 날짜를 주어진 날짜와 비교합니다. Date 인수가 Date와 같으면 0을 반환하고, 그렇지 않으면 0을 반환합니다. Date가 Date 인수보다 앞에 있으면 0보다 작은 값입니다. Date가 Date 인수 뒤에 오면 0보다 큰 값입니다. 긴 getTime() : 이 Date 객체가 나타내는 1970년 1월 1일 00:00:00 GMT 이후의 밀리초 수를 반환합니다. void setTime(긴 시간) : 현재 날짜와 시간을 주어진 시간으로 변경합니다.
    Java
       // Program to demonstrate methods of Date class   import     java.util.*  ;   public     class   Main   {      public     static     void     main  (  String  []     args  )      {      // Creating date      Date     d1     =     new     Date  (  2000       11       21  );      Date     d2     =     new     Date  ();     // Current date      Date     d3     =     new     Date  (  2010       1       3  );      boolean     a     =     d3  .  after  (  d1  );      System  .  out  .  println  (  'Date d3 comes after '     +      'date d2: '     +     a  );      boolean     b     =     d3  .  before  (  d2  );      System  .  out  .  println  (  'Date d3 comes before '  +      'date d2: '     +     b  );      int     c     =     d1  .  compareTo  (  d2  );      System  .  out  .  println  (  c  );      System  .  out  .  println  (  'Miliseconds from Jan 1 '  +      '1970 to date d1 is '     +     d1  .  getTime  ());      System  .  out  .  println  (  'Before setting '  +  d2  );      d2  .  setTime  (  204587433443L  );      System  .  out  .  println  (  'After setting '  +  d2  );      }   }   
    Output:
    Date d3 comes after date d2: true Date d3 comes before date d2: false 1 Miliseconds from Jan 1 1970 to date d1 is 60935500800000 Before setting Tue Jul 12 13:13:16 UTC 2016 After setting Fri Jun 25 21:50:33 UTC 1976