Package com.okta.commons.lang
Class Instants
- java.lang.Object
-
- com.okta.commons.lang.Instants
-
public abstract class Instants extends java.lang.ObjectUtility class to create UTC-based dates and perform time conversions from UTC to othertimezonesand vice versa- Since:
- 0.5.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.TimeZoneUTC_TIMEZONE
-
Constructor Summary
Constructors Constructor Description Instants()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static longconvertDate(long time, java.util.TimeZone from, java.util.TimeZone to)Converts a given time from aTimeZoneto anotherstatic longconvertDateToLocalTime(long time, java.util.TimeZone to)Converts a given time from UTC (Coordinated Universal Time) to the corresponding time in the specifiedTimeZonestatic longconvertDateToUTC(long time, java.util.TimeZone from)Converts a given time from the specifiedTimeZoneto the corresponding UTC (Coordinated Universal Time) timestatic java.util.Dateof(int year)Creates an UTC-basedDateusing the providedyear.static java.util.Dateof(int year, int month)Creates an UTC-basedDatefrom the providedyearandmonth.static java.util.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 java.util.Dateof(int year, int month, int day, int hour)Creates an UTC-basedDatefrom the providedyear,month,dayandhour.static java.util.Dateof(int year, int month, int day, int hour, int minute)Creates an UTC-basedDatefrom the providedyear,month,day,hourandminute.static java.util.Dateof(int year, int month, int day, int hour, int minute, int second)Creates an UTC-basedDatefrom the providedyear,month,day,hour,minuteandsecond.static java.util.Dateof(int year, int month, int day, int hour, int minute, int second, int millisecond)Creates an UTC-basedDatefrom the providedyear,month,day,hour,minuteandsecond.static java.lang.StringtoUtcIso8601(java.util.Date date)Returns the UTC-normalized ISO 8601 representation of the specified date instance.
-
-
-
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 specifiedTimeZone- Parameters:
time- the UTC instant to convert, represented as the number of milliseconds that have elapsed since midnight, January 1, 1970to- the targetTimeZonefor 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 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
public static long convertDate(long time, java.util.TimeZone from, java.util.TimeZone to)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
public static java.util.Date of(int year)
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
public static java.util.Date of(int year, int month)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
public static java.util.Date of(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.- 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
public static java.util.Date of(int year, int month, int day, int hour)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
public static java.util.Date of(int year, int month, int day, int hour, int minute)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
public static java.util.Date of(int year, int month, int day, int hour, int minute, int second)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 java.util.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
-
-