Class DateUtils
- java.lang.Object
-
- com.googlecode.wicket.jquery.core.utils.DateUtils
-
public class DateUtils extends Object
Utility class for dates- Author:
- Sebastien Briquet - sebfz1
-
-
Field Summary
Fields Modifier and Type Field Description static StringDATE_PATTERNdefault java date patternstatic StringISO8601static StringISO8601_TZstatic StringISO8601_UTCstatic StringLOCAL_DATE_PATTERNdefault java 8 date patternstatic StringLOCAL_TIME_PATTERNdefault java 8 time patternstatic StringTIME_PATTERNdefault java time patternstatic TimeZoneUTCUTC timezone
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static longoffset(long time)Gets the current timezone offsetstatic Dateparse(String date)Converts a ISO8601 string date (without timezone) to aDatestatic LocalDatetoLocalDate(long timestamp)Converts a timestamp to aLocalDatestatic LocalDatetoLocalDate(Instant instant)static LocalDateTimetoLocalDateTime(LocalDate date, LocalTime time)static LocalTimetoLocalTime(long timestamp)Converts a timestamp to aLocalTimestatic LocalTimetoLocalTime(Instant instant)static LocalTimetoLocalTime(Date time)static StringtoString(ZonedDateTime date)Converts a date to its ISO8601/javascript representation (with timezone). ie: 2009-11-05T13:15:00.000+0200static StringtoString(Date date)Converts a date to its ISO8601/javascript representation (with timezone). ie: 2009-11-05T13:15:00.000+0200static StringtoUTCString(Date date)Converts a date to its ISO8601/javascript representation (UTC). ie: 2009-11-05T13:15:00.000Zstatic ZonedDateTimetoZonedDateTime(long timestamp, ZoneOffset offset)Converts a timestamp to aZonedDateTimestatic ZonedDateTimetoZonedDateTime(Instant instant, ZoneOffset offset)Converts anInstantto aZonedDateTimestatic ZonedDateTimetoZuluDateTime(long timestamp)Converts a timestamp to an UTCZonedDateTimestatic ZonedDateTimetoZuluDateTime(Instant instant)Converts anInstantto an UTCZonedDateTimestatic longutc()Gets the current UTC datestatic longutc(long date)Converts a local date to a UTC datestatic longutc(Date date)Converts a local date to a UTC date
-
-
-
Field Detail
-
ISO8601
public static final String ISO8601
- See Also:
- Constant Field Values
-
ISO8601_TZ
public static final String ISO8601_TZ
- See Also:
- Constant Field Values
-
ISO8601_UTC
public static final String ISO8601_UTC
- See Also:
- Constant Field Values
-
DATE_PATTERN
public static final String DATE_PATTERN
default java date pattern- See Also:
- Constant Field Values
-
TIME_PATTERN
public static final String TIME_PATTERN
default java time pattern- See Also:
- Constant Field Values
-
LOCAL_DATE_PATTERN
public static final String LOCAL_DATE_PATTERN
default java 8 date pattern- See Also:
- Constant Field Values
-
LOCAL_TIME_PATTERN
public static final String LOCAL_TIME_PATTERN
default java 8 time pattern- See Also:
- Constant Field Values
-
UTC
public static final TimeZone UTC
UTC timezone
-
-
Method Detail
-
utc
public static long utc()
Gets the current UTC date- Returns:
- the current UTC date
-
utc
public static long utc(Date date)
Converts a local date to a UTC date- Parameters:
date- the date to convert- Returns:
- the UTC date
-
utc
public static long utc(long date)
Converts a local date to a UTC date- Parameters:
date- the date to convert- Returns:
- the UTC date
-
offset
public static long offset(long time)
Gets the current timezone offset- Parameters:
time- the timestamp- Returns:
- the timezone offset
- See Also:
TimeZone.getRawOffset()
-
parse
public static Date parse(String date) throws ParseException
Converts a ISO8601 string date (without timezone) to aDate- Parameters:
date- ISO8601 string date- Returns:
- the
Date - Throws:
ParseException- if the string cannot be parsed
-
toString
public static String toString(Date date)
Converts a date to its ISO8601/javascript representation (with timezone). ie: 2009-11-05T13:15:00.000+0200- Parameters:
date- the date to convert- Returns:
- the ISO8601 date as string
-
toString
public static String toString(ZonedDateTime date)
Converts a date to its ISO8601/javascript representation (with timezone). ie: 2009-11-05T13:15:00.000+0200- Parameters:
date- the date to convert- Returns:
- the ISO8601 date as string
-
toUTCString
public static String toUTCString(Date date)
Converts a date to its ISO8601/javascript representation (UTC). ie: 2009-11-05T13:15:00.000Z- Parameters:
date- the date to convert- Returns:
- the ISO8601 date as string
-
toLocalDate
public static LocalDate toLocalDate(long timestamp)
Converts a timestamp to aLocalDate- Parameters:
timestamp- the timestamp- Returns:
- a new
LocalDate
-
toLocalDate
public static LocalDate toLocalDate(Instant instant)
- Parameters:
instant- theInstant- Returns:
- a new
LocalDate
-
toLocalTime
public static LocalTime toLocalTime(Date time)
- Parameters:
time- theDate- Returns:
- a new
LocalTime
-
toLocalTime
public static LocalTime toLocalTime(long timestamp)
Converts a timestamp to aLocalTime- Parameters:
timestamp- the timestamp- Returns:
- a new
LocalTime
-
toLocalTime
public static LocalTime toLocalTime(Instant instant)
- Parameters:
instant- theInstant- Returns:
- a new
LocalTime
-
toLocalDateTime
public static LocalDateTime toLocalDateTime(LocalDate date, LocalTime time)
- Parameters:
date- theLocalDatetime- theLocalTime. Ifnull,LocalTime.MIDNIGHTis returned- Returns:
- a new
LocalDateTime
-
toZuluDateTime
public static ZonedDateTime toZuluDateTime(long timestamp)
Converts a timestamp to an UTCZonedDateTime- Parameters:
timestamp- the timestamp- Returns:
- a new
ZonedDateTime
-
toZuluDateTime
public static ZonedDateTime toZuluDateTime(Instant instant)
Converts anInstantto an UTCZonedDateTime- Parameters:
instant- theInstant- Returns:
- a new
ZonedDateTime
-
toZonedDateTime
public static ZonedDateTime toZonedDateTime(long timestamp, ZoneOffset offset)
Converts a timestamp to aZonedDateTime- Parameters:
timestamp- the timestamp in millisecondsoffset- theZoneOffset- Returns:
- a new
ZonedDateTime
-
toZonedDateTime
public static ZonedDateTime toZonedDateTime(Instant instant, ZoneOffset offset)
Converts anInstantto aZonedDateTime- Parameters:
instant- theInstant- Returns:
- a new
ZonedDateTime
-
-