Modifier and Type | Method and Description |
---|---|
static Date |
fromSecondsSinceEpoch(long time)
Converts the specified Unix epoch time in seconds to a date object.
|
static boolean |
isAfter(Date date,
Date reference,
long maxClockSkewSeconds)
Check if the specified date is after the specified reference, given
the maximum accepted negative clock skew.
|
static boolean |
isBefore(Date date,
Date reference,
long maxClockSkewSeconds)
Checks if the specified date is before the specified reference,
given the maximum accepted positive clock skew.
|
static long |
toSecondsSinceEpoch(Date date)
Converts the specified date object to a Unix epoch time in seconds.
|
public static long toSecondsSinceEpoch(Date date)
date
- The date. Must not be null
.public static Date fromSecondsSinceEpoch(long time)
time
- The Unix epoch time, in seconds. Must not be negative.public static boolean isAfter(Date date, Date reference, long maxClockSkewSeconds)
Formula:
return date + clock_skew > referenceExample: Ensure a JWT expiration (exp) timestamp is after the current time, with a minute of acceptable clock skew.
boolean valid = DateUtils.isAfter(exp, new Date(), 60);
date
- The date to check. Must not be
null
.reference
- The reference date (e.g. the current
time). Must not be null
.maxClockSkewSeconds
- The maximum acceptable negative clock
skew of the date value to check, in
seconds.true
if the date is before the reference, plus the
maximum accepted clock skew, else false
.public static boolean isBefore(Date date, Date reference, long maxClockSkewSeconds)
Formula:
return date - clock_skew < referenceExample: Ensure a JWT issued-at (iat) timestamp is before the current time, with a minute of acceptable clock skew.
boolean valid = DateUtils.isBefore(iat, new Date(), 60);
date
- The date to check. Must not be
null
.reference
- The reference date (e.g. the current
time). Must not be null
.maxClockSkewSeconds
- The maximum acceptable clock skew of the
date value to check, in seconds.true
if the date is before the reference, minus the
maximum accepted clock skew, else false
.Copyright © 2017 Connect2id Ltd.. All rights reserved.