Top Description Fields Constructors Methods
net.fortuna.ical4j.model

public Class Date

extends Iso8601
Class Inheritance
Known Direct Subclasses
net.fortuna.ical4j.model.DateTime
Annotations
@Deprecated
Imports
net.fortuna.ical4j.util.CompatibilityHints, .Dates, .TimeZones, java.text.DateFormat, .ParseException, .SimpleDateFormat, java.util.TimeZone

Deprecated

Use java.time.LocalDate for iCalendar DATE representations.

A representation of the DATE object defined in RFC5445.

Note

iCal4j calculates the timezone of Date objects by default. In the iCalendar specification a DATE object doesn't really have a timezone associated with it, but in the ical4j implementation it does (as it is based on a java.util.Date object). An unfortunate side effect of this is that a Date object can be affected by daylight savings rules for the associated timezone. So currently ical4j offers two approaches to setting the timezone:

  1. Use UTC time (no DST rules, but depending on how the Date is constructed it may change the displayed value
  2. Use local timezone (in rare cases the DST rules may affect the displayed value).

By default option 1 is used, but you can override this with the following flag in the ical4j.properties file: net.fortuna.ical4j.timezone.date.floating=true

Alternatively you can avoid using the constructor that accepts a java.util.Date object, and instead provide a date string value. This should always display the correct value, however when the local timezone is used any calculations (recurrences, etc.) may still be affect by DST rules.

Extract from RFC5545:

3.3.4.  Date

Value Name:  DATE

Purpose:  This value type is used to identify values that contain a
calendar date.

Format Definition:  This value type is defined by the following
notation:

date               = date-value

date-value         = date-fullyear date-month date-mday
date-fullyear      = 4DIGIT
date-month         = 2DIGIT        ;01-12
date-mday          = 2DIGIT        ;01-28, 01-29, 01-30, 01-31
;based on month/year

Description:  If the property permits, multiple "date" values are
specified as a COMMA-separated list of values.  The format for the
value type is based on the [ISO.8601.2004] complete
representation, basic format for a calendar date.  The textual
format specifies a four-digit year, two-digit month, and two-digit
day of the month.  There are no separator characters between the
year, month, and day component text.

No additional content value encoding (i.e., BACKSLASH character
encoding, see Section 3.3.11) is defined for this value type.

Example:  The following represents July 14, 1997:

19970714

Author
Ben Fortuna
Version
2.0

Field Summary

Modifier and TypeField and Description
private static final String
private static final long
private static final String

Constructor Summary

AccessConstructor and Description
public
Date()

Default constructor.

protected
Date(final int
the date precision
precision
,
TimeZone
the timezone
tz
)

Creates a new date instance with the specified precision.

public
Date(final long
a date value in milliseconds
time
)

protected
Date(final long
a date value in milliseconds
time
,
final int
the date precision
precision
,
TimeZone
the timezone
tz
)

Creates a new date instance with the specified precision.

public
Date(final Calendar
a calendar value
calendar
)

public
Date(final Date
a date value
date
)

public
Date(final String
a string representation of a date
value
)

public
Date(String
a string representation of a date
value
,
String
a date pattern to apply when parsing
pattern
)

Method Summary

Inherited from net.fortuna.ical4j.model.Iso8601:
getFormatsetTimetoString

Field Detail

DEFAULT_PATTERNback to summary
private static final String DEFAULT_PATTERN
serialVersionUIDback to summary
private static final long serialVersionUID

Hides net.fortuna.ical4j.model.Iso8601.serialVersionUID.

VCARD_PATTERNback to summary
private static final String VCARD_PATTERN

Constructor Detail

Dateback to summary
public Date()

Default constructor.

Dateback to summary
protected Date(final int precision, TimeZone tz)

Creates a new date instance with the specified precision. This constructor is only intended for use by sub-classes.

Parameters
precision:int

the date precision

tz:TimeZone

the timezone

See Also
Dates#PRECISION_DAY, Dates#PRECISION_SECOND
Dateback to summary
public Date(final long time)
Parameters
time:long

a date value in milliseconds

Dateback to summary
protected Date(final long time, final int precision, TimeZone tz)

Creates a new date instance with the specified precision. This constructor is only intended for use by sub-classes.

Parameters
time:long

a date value in milliseconds

precision:int

the date precision

tz:TimeZone

the timezone

See Also
Dates#PRECISION_DAY, Dates#PRECISION_SECOND
Dateback to summary
public Date(final Calendar calendar)
Parameters
calendar:Calendar

a calendar value

Dateback to summary
public Date(final Date date)
Parameters
date:Date

a date value

Dateback to summary
public Date(final String value) throws ParseException
Parameters
value:String

a string representation of a date

Exceptions
ParseException:
where the specified string is not a valid date
Dateback to summary
public Date(String value, String pattern) throws ParseException
Parameters
value:String

a string representation of a date

pattern:String

a date pattern to apply when parsing

Exceptions
ParseException:
where the specified string is not a valid date