Package de.elo.utils
Class TimeStamp
java.lang.Object
de.elo.utils.TimeStamp
public class TimeStamp
extends java.lang.Object
This class handles the conversion between different date and time formats.
The string representation of
TimeStamp
is an ISO like format with
dots between year, month etc. It is always in UTC.-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_RANGE_DELIM
This delimiter is used by default to separate date-time values. -
Constructor Summary
Constructors Constructor Description TimeStamp()
Default constructor.TimeStamp(int nELODate)
Constructs object from an ELO date.TimeStamp(long nTimeMillis)
Constructor to initialize with a special UTC system time.TimeStamp(TimeStamp ts)
Constructs object from another TimeStamp.TimeStamp(java.lang.String tsStr)
Constructs object from a time stamp string (ISO date with dots).TimeStamp(java.lang.String sISODate, java.util.Locale locale)
Constructs object from an ISO date.TimeStamp(java.lang.String sISODate, java.util.TimeZone tz)
Constructs object from an ISO date.TimeStamp(java.sql.Timestamp sqlTimestamp)
Constructs aTimeStamp
-object from ajava.sql.Timestamp
.TimeStamp(java.time.LocalDateTime ldt)
Constructs a TimeStamp from aLocalDateTime
object.TimeStamp(java.time.LocalDateTime ldt, java.util.TimeZone tz)
Constructs a TimeStamp from aLocalDateTime
andTimeZone
object.TimeStamp(java.util.Date date)
Constructs an object from aDate
object -
Method Summary
Modifier and Type Method Description static java.lang.String
convertISOfromLocaleToLocale(java.lang.String isoDate, java.util.Locale fromLocale, java.util.Locale toLocale)
Convert ISO date from one locale into another.static java.lang.String
convertISOfromLocaleToUTC(java.lang.String isoDate)
Convert ISO date measured in the default locale to the corresponding ISO date in UTC.static java.lang.String
convertISOfromLocaleToUTC(java.lang.String isoDate, java.util.Locale locale)
Convert ISO date measured in the specified locale to the corresponding ISO date in UTC.static java.lang.String
convertISOfromTztoTz(java.lang.String isoDate, java.util.TimeZone fromTz, java.util.TimeZone toTz)
Convert ISO date from one timezone into another.static java.lang.String
convertISOfromTzToUTC(java.lang.String isoDate, java.util.TimeZone fromTz)
Convert ISO date from timezone into UTC.static java.lang.String
convertISOfromUTCtoLocale(java.lang.String isoDate)
Convert ISO date measured in UTC to the corresponding ISO date measured in the default locale.static java.lang.String
convertISOfromUTCtoLocale(java.lang.String isoDate, java.util.Locale locale)
Convert ISO date measured in UTC to the corresponding ISO date measured in the specified locale.static java.lang.String
convertISOfromUTCtoTz(java.lang.String isoDate, java.util.TimeZone toTz)
Convert ISO date from UTC timezone into another.static int
convertToEloDate(java.lang.String isoDate, java.util.TimeZone tz)
Converts an ISO date string of given timezone into an ELO date in the default timezone of the VM.boolean
equals(java.lang.Object obj)
int
hashCode()
static TimeStamp
now()
Creates a newTimeStamp
object initialized with the current time.static TimeStamp
oldest()
Creates a newTimeStamp
object initialized with the oldest valid time.java.util.Date
toDate()
Converts toDate
int
toELODate()
Converts to ELO date format.java.lang.String
toISODate()
Converts to ISO date.java.lang.String
toISODate(java.util.Locale locale)
Converts to ISO date measured in the specified time zone.java.lang.String
toISODate(java.util.TimeZone tz)
Converts to ISO date measured in the specified time zone.java.lang.String
toISODateUTC()
Converts to ISO date.java.time.LocalDateTime
toLocalDateTime()
Converts to LocalDateTime with UTC as TimeZonejava.time.LocalDateTime
toLocalDateTime(java.util.TimeZone tz)
Converts to LocalDateTime with a given TimeZonejava.sql.Timestamp
toSqlTimestamp()
java.lang.String
toString()
Returns the string representation ofthis
.java.lang.String
toString(java.util.TimeZone tz)
Convert to string representation in given timezone.long
toTimeMillis()
Returns the system time millis (UTC).
-
Field Details
-
DEFAULT_RANGE_DELIM
public static final java.lang.String DEFAULT_RANGE_DELIMThis delimiter is used by default to separate date-time values.- See Also:
- Constant Field Values
-
-
Constructor Details
-
TimeStamp
public TimeStamp()Default constructor. Initializes the object with the current date. -
TimeStamp
public TimeStamp(long nTimeMillis)Constructor to initialize with a special UTC system time.- Parameters:
nTimeMillis
- UTC milliseconds
-
TimeStamp
public TimeStamp(int nELODate)Constructs object from an ELO date. ELO date values are always measured in the local time zone of the server.- Parameters:
nELODate
- proprietary ELO date value
-
TimeStamp
public TimeStamp(java.lang.String tsStr)Constructs object from a time stamp string (ISO date with dots). Time stamp strings are always measured in the UTC time zone. It's also possible to supply an ISO date (without dots) in tsStr. This ISO date is assumed to be in UTC time zone.- Parameters:
tsStr
- Time stamp string
-
TimeStamp
public TimeStamp(java.lang.String sISODate, java.util.TimeZone tz)Constructs object from an ISO date.- Parameters:
sISODate
- ISO datetz
- Time zone ofsISODate
. Ifnull
the current default time zone is used.
-
TimeStamp
public TimeStamp(java.lang.String sISODate, java.util.Locale locale)Constructs object from an ISO date.- Parameters:
sISODate
- ISO datelocale
-sISODate
is assumed to be in the default time zone of this locale. Ifnull
the current default time zone is used.
-
TimeStamp
Constructs object from another TimeStamp.- Parameters:
ts
- Other TimeStamp
-
TimeStamp
public TimeStamp(java.sql.Timestamp sqlTimestamp)Constructs aTimeStamp
-object from ajava.sql.Timestamp
.- Parameters:
sqlTimestamp
-
-
TimeStamp
public TimeStamp(java.util.Date date)Constructs an object from aDate
object- Parameters:
date
- Date object (is cloned)
-
TimeStamp
public TimeStamp(java.time.LocalDateTime ldt)Constructs a TimeStamp from aLocalDateTime
object. -
TimeStamp
public TimeStamp(java.time.LocalDateTime ldt, java.util.TimeZone tz)Constructs a TimeStamp from aLocalDateTime
andTimeZone
object.- Parameters:
ldt
-tz
-
-
-
Method Details
-
now
Creates a newTimeStamp
object initialized with the current time.- Returns:
- New TimeStamp object
-
oldest
Creates a newTimeStamp
object initialized with the oldest valid time.- Returns:
- New TimeStamp object
-
toString
public java.lang.String toString()Returns the string representation ofthis
.- Overrides:
toString
in classjava.lang.Object
- Returns:
- Time string (with dots) - always measured in UTC
- See Also:
toString(TimeZone)
-
toString
public java.lang.String toString(java.util.TimeZone tz)Convert to string representation in given timezone.- Parameters:
tz
- TimeZone- Returns:
- String representation, e.g. "2010.09.08.13.14.15"
-
toDate
public final java.util.Date toDate()Converts toDate
- Returns:
- Date object
-
toELODate
public final int toELODate()Converts to ELO date format.- Returns:
- ELO date. ELO date values are always measured in the local time zone of the server.
-
toISODate
public final java.lang.String toISODate()Converts to ISO date.- Returns:
- ISO date measured in the default time zone.
- See Also:
toISODate(TimeZone)
-
toISODateUTC
public final java.lang.String toISODateUTC()Converts to ISO date.- Returns:
- ISO date measured in the UTC time zone.
- See Also:
toISODate(TimeZone)
-
toISODate
public final java.lang.String toISODate(java.util.TimeZone tz)Converts to ISO date measured in the specified time zone.- Parameters:
tz
- Time zone. Ifnull
the default time zone is used- Returns:
- ISO date
-
toISODate
public final java.lang.String toISODate(java.util.Locale locale)Converts to ISO date measured in the specified time zone.- Parameters:
locale
- Locale of returned ISO date. Ifnull
the default time zone is used.- Returns:
- ISO date
-
toLocalDateTime
public final java.time.LocalDateTime toLocalDateTime()Converts to LocalDateTime with UTC as TimeZone- Returns:
- LocalDateTime
-
toLocalDateTime
public final java.time.LocalDateTime toLocalDateTime(java.util.TimeZone tz)Converts to LocalDateTime with a given TimeZone- Parameters:
tz
- - TimeZone to use.- Returns:
- LocalDateTime
-
toSqlTimestamp
public final java.sql.Timestamp toSqlTimestamp() -
toTimeMillis
public final long toTimeMillis()Returns the system time millis (UTC).- Returns:
- System time millis
-
convertISOfromLocaleToUTC
public static final java.lang.String convertISOfromLocaleToUTC(java.lang.String isoDate, java.util.Locale locale)Convert ISO date measured in the specified locale to the corresponding ISO date in UTC.- Parameters:
isoDate
- ISO datelocale
- Locale ofisoDate
- Returns:
- UTC date
-
convertISOfromLocaleToUTC
public static final java.lang.String convertISOfromLocaleToUTC(java.lang.String isoDate)Convert ISO date measured in the default locale to the corresponding ISO date in UTC.- Parameters:
isoDate
- ISO date- Returns:
- UTC date
-
convertISOfromUTCtoLocale
public static final java.lang.String convertISOfromUTCtoLocale(java.lang.String isoDate, java.util.Locale locale)Convert ISO date measured in UTC to the corresponding ISO date measured in the specified locale.- Parameters:
isoDate
- ISO date in UTClocale
- Locale of the returned date- Returns:
- ISO date measured in the specified locale
-
convertISOfromUTCtoLocale
public static final java.lang.String convertISOfromUTCtoLocale(java.lang.String isoDate)Convert ISO date measured in UTC to the corresponding ISO date measured in the default locale.- Parameters:
isoDate
- ISO date in UTC- Returns:
- ISO date measured in the specified locale
-
convertISOfromLocaleToLocale
public static final java.lang.String convertISOfromLocaleToLocale(java.lang.String isoDate, java.util.Locale fromLocale, java.util.Locale toLocale)Convert ISO date from one locale into another.- Parameters:
isoDate
- ISO date in UTCfromLocale
- Locale ofisoDate
toLocale
- Locale of the returned date- Returns:
- ISO date
-
convertISOfromTztoTz
public static final java.lang.String convertISOfromTztoTz(java.lang.String isoDate, java.util.TimeZone fromTz, java.util.TimeZone toTz)Convert ISO date from one timezone into another.- Parameters:
isoDate
- ISO date in UTCfromTz
- Timezone ofisoDate
toTz
- Timezone of the returned date- Returns:
- ISO date
-
convertISOfromUTCtoTz
public static final java.lang.String convertISOfromUTCtoTz(java.lang.String isoDate, java.util.TimeZone toTz)Convert ISO date from UTC timezone into another.- Parameters:
isoDate
- ISO date in UTCtoTz
- Timezone of the returned date- Returns:
- ISO date
-
convertISOfromTzToUTC
public static final java.lang.String convertISOfromTzToUTC(java.lang.String isoDate, java.util.TimeZone fromTz)Convert ISO date from timezone into UTC.- Parameters:
isoDate
- ISO date in timezone fromTzfromTz
- Timezone of ISO date- Returns:
- UTC
-
convertToEloDate
public static final int convertToEloDate(java.lang.String isoDate, java.util.TimeZone tz)Converts an ISO date string of given timezone into an ELO date in the default timezone of the VM.- Parameters:
isoDate
- Stringtz
- TimeZone- Returns:
- int
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equals
in classjava.lang.Object
-