Class Date


  • public class Date
    extends java.lang.Object
    Simple class which represents immutable dates that are consisted of day, month and year.
    • Constructor Summary

      Constructors 
      Constructor Description
      Date​(int day, int month, int year)
      Initializes the object with the given day, month and year.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getDay()
      Returns day of the month, or 0 if date is partial and day is not known.
      int getMonth()
      Returns month of the year, or 0 if date is partial and month is not known.
      int getYear()
      Returns full year.
      static Date parseFromString​(java.lang.String dateString, java.lang.String pattern)
      Creates Date instance by parsing the given dateString, by using the given pattern which describes the date format.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Date

        public Date​(int day,
                    int month,
                    int year)
        Initializes the object with the given day, month and year.
        Parameters:
        day - Day of the month. The first day of the month has value 1.
        month - Month of the year. The first month of the year has value 1.
        year - Full year.
    • Method Detail

      • getDay

        public int getDay()
        Returns day of the month, or 0 if date is partial and day is not known.
        Returns:
        day of the month, or 0 if date is partial and day is not known. The first day of the month has value 1.
      • getMonth

        public int getMonth()
        Returns month of the year, or 0 if date is partial and month is not known.
        Returns:
        month of the year, or 0 if date is partial and month is not known. The first month of the year has value 1.
      • getYear

        public int getYear()
        Returns full year.
        Returns:
        full year.
      • parseFromString

        @Nullable
        public static Date parseFromString​(@NonNull
                                           java.lang.String dateString,
                                           @NonNull
                                           java.lang.String pattern)
        Creates Date instance by parsing the given dateString, by using the given pattern which describes the date format.
        Parameters:
        dateString - A String whose beginning should be parsed.
        pattern - the pattern describing the date format, formatting is the same as in SimpleDateFormat.
        Returns:
        parsed date as Date instance, or null if the dateString cannot be parsed.
        Throws:
        java.lang.IllegalArgumentException - if the given pattern is invalid
      • toString

        @NonNull
        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object