public class InternetDateFormat
extends java.text.DateFormat
In addition to the static utility methods, this class also wraps a Calendar object allowing this class to be used as a value object in place of a Java construct.
Strings are parsed in accordance with the RFC 3339 format:
YYYY-MM-DD(T|t|\s)hh:mm:ss[.ddd][tzd]The
tzd
represents the time zone designator and is either an
upper or lower case 'Z' indicating UTC or a signed hh:mm
offset.Modifier and Type | Field and Description |
---|---|
static java.util.TimeZone |
UTC
A time zone with zero offset and no DST.
|
AM_PM_FIELD, calendar, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, numberFormat, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD
Constructor and Description |
---|
InternetDateFormat()
Creates a new InternetDateFormat object set to the current time using the
UTC (Z) time zone.
|
InternetDateFormat(java.util.Calendar cal)
Creates a new InternetDateFormat object initialized from a Calendar
object.
|
InternetDateFormat(java.util.Date date)
Creates a new InternetDateFormat object initialized from a Date object
using the UTC (Z) time zone.
|
InternetDateFormat(java.util.Date date,
java.util.TimeZone zone)
Creates a new InternetDateFormat object initialized from a Date object
using the specified time zone.
|
InternetDateFormat(long time)
Creates a new InternetDateFormat object initialized from a millisecond
time value using the UTC (Z) time zone.
|
InternetDateFormat(long time,
java.util.TimeZone zone)
Creates a new InternetDateFormat object initialized from a millisecond
time value using the specified time zone.
|
InternetDateFormat(java.lang.String s)
Creates a new InternetDateFormat object by parsing an RFC 3339 date/time
string.
|
InternetDateFormat(java.util.TimeZone zone)
Creates a new InternetDateFormat object set to the current time using the
specified time zone.
|
Modifier and Type | Method and Description |
---|---|
java.lang.StringBuffer |
format(java.util.Date date,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition fieldPosition) |
java.util.Calendar |
getCalendar()
Gets the Calendar object wrapped by this InternetDateFormat object.
|
java.util.Date |
getDate()
Gets the value of this InternetDateFormat object as a Date object.
|
long |
getTime()
Gets the value of this InternetDateFormat object as millisecond time
value.
|
static java.lang.String |
now()
Returns the current date and time as an RFC 3339 date/time string using
the UTC (Z) time zone.
|
static java.lang.String |
now(java.util.TimeZone zone)
Returns the current date and time as an RFC 3339 date/time string using
the specified time zone.
|
java.util.Date |
parse(java.lang.String source) |
java.util.Date |
parse(java.lang.String source,
java.text.ParsePosition pos) |
static java.util.Calendar |
parseCalendar(java.lang.String s)
Parses an RFC 3339 date/time string to a Calendar object.
|
static java.util.Date |
parseDate(java.lang.String s)
Parses an RFC 3339 date/time string to a Date object.
|
static long |
parseTime(java.lang.String s)
Parses an RFC 3339 date/time string to a millisecond time value.
|
java.lang.String |
toString()
Converts this InternetDateFormat object to an RFC 3339 date/time string.
|
static java.lang.String |
toString(java.util.Calendar cal)
Converts the specified Calendar object to an RFC 3339 date/time string.
|
static java.lang.String |
toString(java.util.Date date)
Converts the specified Date object to an RFC 3339 date/time string using
the UTC (Z) time zone.
|
static java.lang.String |
toString(java.util.Date date,
java.util.TimeZone zone)
Converts the specified Date object to an RFC 3339 date/time string using
the specified time zone.
|
static java.lang.String |
toString(long time)
Converts the specified millisecond time value to an RFC 3339 date/time
string using the UTC (Z) time zone.
|
static java.lang.String |
toString(long time,
java.util.TimeZone zone)
Converts the specified millisecond time value to an RFC 3339 date/time
string using the specified time zone.
|
static InternetDateFormat |
valueOf(java.util.Date date)
Creates a new InternetDateFormat object from the specified Date object
using the UTC (Z) time zone.
|
static InternetDateFormat |
valueOf(java.util.Date date,
java.util.TimeZone zone)
Creates a new InternetDateFormat object from the specified Date object
using the specified time zone.
|
static InternetDateFormat |
valueOf(long time)
Creates a new InternetDateFormat object from the specified millisecond
time value using the UTC (Z) time zone.
|
static InternetDateFormat |
valueOf(long time,
java.util.TimeZone zone)
Creates a new InternetDateFormat object from the specified millisecond
time value using the specified time zone.
|
static InternetDateFormat |
valueOf(java.lang.String s)
Creates a new InternetDateFormat object by parsing an RFC 3339 date/time
string.
|
clone, equals, format, format, getAvailableLocales, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, hashCode, isLenient, parseObject, setCalendar, setLenient, setNumberFormat, setTimeZone
public static final java.util.TimeZone UTC
public InternetDateFormat()
public InternetDateFormat(java.util.Calendar cal)
cal
- the Calendar objectpublic InternetDateFormat(java.util.Date date)
date
- the Date objectpublic InternetDateFormat(java.util.Date date, java.util.TimeZone zone)
date
- the Date objectzone
- the time zone to usepublic InternetDateFormat(long time)
time
- the millisecond time valuepublic InternetDateFormat(long time, java.util.TimeZone zone)
time
- the millisecond time valuezone
- the time zone to usepublic InternetDateFormat(java.lang.String s)
s
- the string to parsejava.lang.IllegalArgumentException
- if the string is not a valid RFC 3339 date/time stringpublic InternetDateFormat(java.util.TimeZone zone)
zone
- the time zone to usepublic static java.lang.String now()
public static java.lang.String now(java.util.TimeZone zone)
zone
- the time zone to usepublic static java.util.Calendar parseCalendar(java.lang.String s)
s
- the string to parsejava.lang.IllegalArgumentException
- if the string is not a valid RFC 3339 date/time stringpublic static java.util.Date parseDate(java.lang.String s)
s
- the string to parsejava.lang.IllegalArgumentException
- if the string is not a valid RFC 3339 date/time stringpublic static long parseTime(java.lang.String s)
s
- the string to parsejava.lang.IllegalArgumentException
- if the string is not a valid RFC 3339 date/time stringpublic static java.lang.String toString(java.util.Calendar cal)
cal
- the Calendar objectpublic static java.lang.String toString(java.util.Date date)
date
- the Date objectpublic static java.lang.String toString(java.util.Date date, java.util.TimeZone zone)
date
- the Date objectzone
- the time zone to usepublic static java.lang.String toString(long time)
time
- the millisecond time valuepublic static java.lang.String toString(long time, java.util.TimeZone zone)
time
- the millisecond time valuezone
- the time zone to usepublic static InternetDateFormat valueOf(java.util.Date date)
date
- the Date objectpublic static InternetDateFormat valueOf(java.util.Date date, java.util.TimeZone zone)
date
- the Date objectzone
- the time zone to usepublic static InternetDateFormat valueOf(long time)
time
- the millisecond time valuepublic static InternetDateFormat valueOf(long time, java.util.TimeZone zone)
time
- the millisecond time valuezone
- the time zone to usepublic static InternetDateFormat valueOf(java.lang.String s)
s
- the string to parsejava.lang.IllegalArgumentException
- if the string is not a valid RFC 3339 date/time stringpublic java.lang.StringBuffer format(java.util.Date date, java.lang.StringBuffer toAppendTo, java.text.FieldPosition fieldPosition)
format
in class java.text.DateFormat
public java.util.Calendar getCalendar()
getCalendar
in class java.text.DateFormat
public java.util.Date getDate()
public long getTime()
public java.util.Date parse(java.lang.String source) throws java.text.ParseException
parse
in class java.text.DateFormat
java.text.ParseException
public java.util.Date parse(java.lang.String source, java.text.ParsePosition pos)
parse
in class java.text.DateFormat
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2005-2024 Restlet.