Package io.sentry
Class DateUtils
java.lang.Object
io.sentry.DateUtils
Utilities to deal with dates
-
Method Summary
Modifier and TypeMethodDescriptionstatic long
dateToNanos
(@NotNull Date date) static double
dateToSeconds
(@NotNull Date date) static @NotNull Date
Get the current Date (UTC)static @NotNull Date
getDateTime
(long millis) Get the Date from millis timestampstatic @NotNull Date
getDateTime
(@NotNull String timestamp) Get the Date from UTC/ISO 8601 timestampstatic @NotNull Date
getDateTimeWithMillisPrecision
(@NotNull String timestamp) Get the Date from millis timestampstatic @NotNull String
getTimestamp
(@NotNull Date date) Get the UTC/ISO 8601 timestamp from Datestatic long
millisToNanos
(long millis) static double
millisToSeconds
(double millis) Converts milliseconds to seconds.static Date
nanosToDate
(long nanos) Converts nanoseconds toDate
rounded down to millisecondsstatic double
nanosToMillis
(double nanos) Converts nanoseconds to millisecondsstatic double
nanosToSeconds
(long nanos) Converts nanoseconds to secondsstatic long
secondsToNanos
(@org.jetbrains.annotations.NotNull long seconds) static @Nullable Date
toUtilDate
(@Nullable SentryDate sentryDate) static @NotNull Date
toUtilDateNotNull
(@NotNull SentryDate sentryDate)
-
Method Details
-
getCurrentDateTime
Get the current Date (UTC)- Returns:
- the UTC Date
-
getDateTime
@NotNull public static @NotNull Date getDateTime(@NotNull @NotNull String timestamp) throws IllegalArgumentException Get the Date from UTC/ISO 8601 timestamp- Parameters:
timestamp
- UTC/ISO 8601 format eg 2000-12-31T23:59:58Z or 2000-12-31T23:59:58.123Z- Returns:
- the UTC Date
- Throws:
IllegalArgumentException
-
getDateTimeWithMillisPrecision
@NotNull public static @NotNull Date getDateTimeWithMillisPrecision(@NotNull @NotNull String timestamp) throws IllegalArgumentException Get the Date from millis timestamp- Parameters:
timestamp
- millis eg 1581410911.988 (1581410911 seconds and 988 millis)- Returns:
- the UTC Date
- Throws:
IllegalArgumentException
-
getTimestamp
Get the UTC/ISO 8601 timestamp from Date- Parameters:
date
- the UTC Date- Returns:
- the UTC/ISO 8601 timestamp
-
getDateTime
Get the Date from millis timestamp- Parameters:
millis
- the UTC millis from the epoch- Returns:
- the UTC Date
-
millisToSeconds
public static double millisToSeconds(double millis) Converts milliseconds to seconds.- Parameters:
millis
- - milliseconds- Returns:
- seconds
-
millisToNanos
public static long millisToNanos(long millis) -
nanosToMillis
public static double nanosToMillis(double nanos) Converts nanoseconds to milliseconds- Parameters:
nanos
- - nanoseconds- Returns:
- milliseconds
-
nanosToDate
Converts nanoseconds toDate
rounded down to milliseconds- Parameters:
nanos
- - nanoseconds- Returns:
- date rounded down to milliseconds
-
toUtilDate
-
toUtilDateNotNull
-
nanosToSeconds
public static double nanosToSeconds(long nanos) Converts nanoseconds to seconds- Parameters:
nanos
- - nanoseconds- Returns:
- seconds
-
dateToSeconds
- Parameters:
date
- - date- Returns:
- seconds
-
dateToNanos
- Parameters:
date
- - date- Returns:
- nanoseconds
-
secondsToNanos
public static long secondsToNanos(@NotNull @org.jetbrains.annotations.NotNull long seconds)
-