Class Instants


  • public abstract class Instants
    extends java.lang.Object
    Utility class to create UTC-based dates and perform time conversions from UTC to other timezones and vice versa
    Since:
    0.5.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.TimeZone UTC_TIMEZONE  
    • Constructor Summary

      Constructors 
      Constructor Description
      Instants()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long convertDate​(long time, java.util.TimeZone from, java.util.TimeZone to)
      Converts a given time from a TimeZone to another
      static long convertDateToLocalTime​(long time, java.util.TimeZone to)
      Converts a given time from UTC (Coordinated Universal Time) to the corresponding time in the specified TimeZone
      static long convertDateToUTC​(long time, java.util.TimeZone from)
      Converts a given time from the specified TimeZone to the corresponding UTC (Coordinated Universal Time) time
      static java.util.Date of​(int year)
      Creates an UTC-based Date using the provided year.
      static java.util.Date of​(int year, int month)
      Creates an UTC-based Date from the provided year and month.
      static java.util.Date of​(int year, int month, int day)
      Creates an UTC-based Date from the provided year, month and day Uses the current date and time, sets the specified year, month and day, and returns the Date converted to a UTC timestamp.
      static java.util.Date of​(int year, int month, int day, int hour)
      Creates an UTC-based Date from the provided year, month, day and hour.
      static java.util.Date of​(int year, int month, int day, int hour, int minute)
      Creates an UTC-based Date from the provided year, month, day, hour and minute.
      static java.util.Date of​(int year, int month, int day, int hour, int minute, int second)
      Creates an UTC-based Date from the provided year, month, day, hour, minute and second.
      static java.util.Date of​(int year, int month, int day, int hour, int minute, int second, int millisecond)
      Creates an UTC-based Date from the provided year, month, day, hour, minute and second.
      static java.lang.String toUtcIso8601​(java.util.Date date)
      Returns the UTC-normalized ISO 8601 representation of the specified date instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • UTC_TIMEZONE

        public static final java.util.TimeZone UTC_TIMEZONE
    • Constructor Detail

      • Instants

        public Instants()
    • Method Detail

      • toUtcIso8601

        public static java.lang.String toUtcIso8601​(java.util.Date date)
        Returns the UTC-normalized ISO 8601 representation of the specified date instance.
        Parameters:
        date - the date to format.
        Returns:
        the UTC-normalized ISO 8601 representation of the specified date instance.
      • convertDateToLocalTime

        public static long convertDateToLocalTime​(long time,
                                                  java.util.TimeZone to)
        Converts a given time from UTC (Coordinated Universal Time) to the corresponding time in the specified TimeZone
        Parameters:
        time - the UTC instant to convert, represented as the number of milliseconds that have elapsed since midnight, January 1, 1970
        to - the target TimeZone for the conversion
        Returns:
        the long representation of the instant converted to the specified TimeZone
      • convertDateToUTC

        public static long convertDateToUTC​(long time,
                                            java.util.TimeZone from)
        Converts a given time from the specified TimeZone to the corresponding UTC (Coordinated Universal Time) time
        Parameters:
        time - the instant to convert, represented as the number of milliseconds that have elapsed since midnight, January 1, 1970
        from - the original TimeZone
        Returns:
        the UTC instant, represented as the number of milliseconds that have elapsed since midnight, January 1, 1970
      • convertDate

        public static long convertDate​(long time,
                                       java.util.TimeZone from,
                                       java.util.TimeZone to)
        Converts a given time from a TimeZone to another
        Parameters:
        time - the instant to convert, represented as the number of milliseconds that have elapsed since midnight, January 1, 1970 in the from TimeZone
        from - the original TimeZone
        to - the target TimeZone for the conversion
        Returns:
        the long representation of the instant converted to the specified to TimeZone
      • of

        public static java.util.Date of​(int year)
        Creates an UTC-based Date using the provided year. Uses the current date and time, sets the specified year and returns the Date converted to a UTC timestamp.
        Parameters:
        year - the year to represent
        Returns:
        the UTC-based Date
      • of

        public static java.util.Date of​(int year,
                                        int month)
        Creates an UTC-based Date from the provided year and month. Uses the current date and time, sets the specified year and month, and returns the Date converted to a UTC timestamp.
        Parameters:
        year - the year to represent
        month - the month-of-year to represent, from 0 (January) to 11 (December)
        Returns:
        the UTC-based Date
      • of

        public static java.util.Date of​(int year,
                                        int month,
                                        int day)
        Creates an UTC-based Date from the provided year, month and day Uses the current date and time, sets the specified year, month and day, and returns the Date converted to a UTC timestamp.
        Parameters:
        year - the year to represent
        month - the month-of-year to represent, from 0 (January) to 11 (December)
        day - the day-of-month to represent, from 1 to 31
        Returns:
        the UTC-based Date
      • of

        public static java.util.Date of​(int year,
                                        int month,
                                        int day,
                                        int hour)
        Creates an UTC-based Date from the provided year, month, day and hour. Uses the current date and time, sets the specified year, month, day and hour, and returns the Date converted to a UTC timestamp.
        Parameters:
        year - the year to represent
        month - the month-of-year to represent, from 0 (January) to 11 (December)
        day - the day-of-month to represent, from 1 to 31
        hour - the hour-of-day to represent, from 0 to 23
        Returns:
        the UTC-based Date
      • of

        public static java.util.Date of​(int year,
                                        int month,
                                        int day,
                                        int hour,
                                        int minute)
        Creates an UTC-based Date from the provided year, month, day, hour and minute. Uses the current date and time, sets the specified year, month, day, hour and minute, and returns the Date converted to a UTC timestamp.
        Parameters:
        year - the year to represent
        month - the month-of-year to represent, from 0 (January) to 11 (December)
        day - the day-of-month to represent, from 1 to 31
        hour - the hour-of-day to represent, from 0 to 23
        minute - the minute-of-hour to represent, from 0 to 59
        Returns:
        the UTC-based Date
      • of

        public static java.util.Date of​(int year,
                                        int month,
                                        int day,
                                        int hour,
                                        int minute,
                                        int second)
        Creates an UTC-based Date from the provided year, month, day, hour, minute and second. Uses the current date and time, sets the specified year, month, day, hour, minute and second, and returns the Date converted to a UTC timestamp.
        Parameters:
        year - the year to represent
        month - the month-of-year to represent, from 0 (January) to 11 (December)
        day - the day-of-month to represent, from 1 to 31
        hour - the hour-of-day to represent, from 0 to 23
        minute - the minute-of-hour to represent, from 0 to 59
        second - the second-of-hour to represent, from 0 to 59
        Returns:
        the UTC-based Date
      • of

        public static java.util.Date of​(int year,
                                        int month,
                                        int day,
                                        int hour,
                                        int minute,
                                        int second,
                                        int millisecond)
        Creates an UTC-based Date from the provided year, month, day, hour, minute and second. Uses the current date and time, sets the specified year, month, day, hour, minute and second, and returns the Date converted to a UTC timestamp.
        Parameters:
        year - the YEAR to represent
        month - the MONTH to represent, from 0 (January) to 11 (December)
        day - the DAY_OF_MONTH to represent, from 1 to 31
        hour - the HOUR_OF_DAY to represent, from 0 to 23
        minute - the MINUTE to represent, from 0 to 59
        second - the SECOND to represent, from 0 to 59
        millisecond - the MILLISECOND to represent, from 0 to 59
        Returns:
        the UTC-based Date