Package com.okta.commons.lang
Class Instants
java.lang.Object
com.okta.commons.lang.Instants
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longconvertDate(long time, TimeZone from, TimeZone to) Converts a given time from aTimeZoneto anotherstatic longconvertDateToLocalTime(long time, TimeZone to) Converts a given time from UTC (Coordinated Universal Time) to the corresponding time in the specifiedTimeZonestatic longconvertDateToUTC(long time, TimeZone from) Converts a given time from the specifiedTimeZoneto the corresponding UTC (Coordinated Universal Time) timestatic Dateof(int year) Creates an UTC-basedDateusing the providedyear.static Dateof(int year, int month) static Dateof(int year, int month, int day) Creates an UTC-basedDatefrom the providedyear,monthanddayUses the current date and time, sets the specifiedyear,monthandday, and returns the Date converted to a UTC timestamp.static Dateof(int year, int month, int day, int hour) static Dateof(int year, int month, int day, int hour, int minute) static Dateof(int year, int month, int day, int hour, int minute, int second) static Dateof(int year, int month, int day, int hour, int minute, int second, int millisecond) static StringtoUtcIso8601(Date date) Returns the UTC-normalized ISO 8601 representation of the specified date instance.
-
Field Details
-
UTC_TIMEZONE
-
-
Constructor Details
-
Instants
public Instants()
-
-
Method Details
-
toUtcIso8601
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
Converts a given time from UTC (Coordinated Universal Time) to the corresponding time in the specifiedTimeZone -
convertDateToUTC
Converts a given time from the specifiedTimeZoneto 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, 1970from- the originalTimeZone- Returns:
- the UTC instant, represented as the number of milliseconds that have elapsed since midnight, January 1, 1970
-
convertDate
Converts a given time from aTimeZoneto another- Parameters:
time- the instant to convert, represented as the number of milliseconds that have elapsed since midnight, January 1, 1970 in thefromTimeZonefrom- the originalTimeZoneto- the targetTimeZonefor the conversion- Returns:
- the long representation of the instant converted to the specified
toTimeZone
-
of
Creates an UTC-basedDateusing the providedyear. Uses the current date and time, sets the specifiedyearand returns the Date converted to a UTC timestamp.- Parameters:
year- the year to represent- Returns:
- the UTC-based
Date
-
of
Creates an UTC-basedDatefrom the providedyearandmonth. Uses the current date and time, sets the specifiedyearandmonth, and returns the Date converted to a UTC timestamp.- Parameters:
year- the year to representmonth- the month-of-year to represent, from 0 (January) to 11 (December)- Returns:
- the UTC-based
Date
-
of
Creates an UTC-basedDatefrom the providedyear,monthanddayUses the current date and time, sets the specifiedyear,monthandday, and returns the Date converted to a UTC timestamp.- Parameters:
year- the year to representmonth- 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
Creates an UTC-basedDatefrom the providedyear,month,dayandhour. Uses the current date and time, sets the specifiedyear,month,dayandhour, and returns the Date converted to a UTC timestamp.- Parameters:
year- the year to representmonth- the month-of-year to represent, from 0 (January) to 11 (December)day- the day-of-month to represent, from 1 to 31hour- the hour-of-day to represent, from 0 to 23- Returns:
- the UTC-based
Date
-
of
Creates an UTC-basedDatefrom the providedyear,month,day,hourandminute. Uses the current date and time, sets the specifiedyear,month,day,hourandminute, and returns the Date converted to a UTC timestamp.- Parameters:
year- the year to representmonth- the month-of-year to represent, from 0 (January) to 11 (December)day- the day-of-month to represent, from 1 to 31hour- the hour-of-day to represent, from 0 to 23minute- the minute-of-hour to represent, from 0 to 59- Returns:
- the UTC-based
Date
-
of
Creates an UTC-basedDatefrom the providedyear,month,day,hour,minuteandsecond. Uses the current date and time, sets the specifiedyear,month,day,hour,minuteandsecond, and returns the Date converted to a UTC timestamp.- Parameters:
year- the year to representmonth- the month-of-year to represent, from 0 (January) to 11 (December)day- the day-of-month to represent, from 1 to 31hour- the hour-of-day to represent, from 0 to 23minute- the minute-of-hour to represent, from 0 to 59second- the second-of-hour to represent, from 0 to 59- Returns:
- the UTC-based
Date
-
of
public static Date of(int year, int month, int day, int hour, int minute, int second, int millisecond) Creates an UTC-basedDatefrom the providedyear,month,day,hour,minuteandsecond. Uses the current date and time, sets the specifiedyear,month,day,hour,minuteandsecond, and returns the Date converted to a UTC timestamp.- Parameters:
year- the YEAR to representmonth- the MONTH to represent, from 0 (January) to 11 (December)day- the DAY_OF_MONTH to represent, from 1 to 31hour- the HOUR_OF_DAY to represent, from 0 to 23minute- the MINUTE to represent, from 0 to 59second- the SECOND to represent, from 0 to 59millisecond- the MILLISECOND to represent, from 0 to 59- Returns:
- the UTC-based
Date
-