DateTime (Java)

Represents a date and time.

Syntax

public class DateTime extends Base

Containment

Contained by: AgentContext, Database, DateRange, DateTime, Document, Session, and View

Properties

DateOnly through getDateOnly

GMTTime through getGMTTime

IsDST through isDST

LocalTime through getLocalTime, setLocalTime, and setLocalDate

Parent through getParent

TimeOnly through getTimeOnly

TimeZone through getTimeZone

ZoneTime through getZoneTime

Methods

adjustDay

adjustHour

adjustMinute

adjustMonth

adjustSecond

adjustYear

convertToZone

recycle

setAnyDate

setAnyTime

setNow

timeDifference

toJavaDate

toString

Creation

To create a new DateTime object, use createDateTime in Session.

Usage

After creating a DateTime object with createDateTime, you can reset the date and time with setLocalTime and setLocalDate. The createDateTime method takes a String, java.util.Date, or java.util.Calendar parameter. One form of setLocalTime takes a String parameter, another form takes a java.util.Date parameter, and a third form takes a java.util.Calendar parameter. Other forms of setLocalTime and setLocalDate take multiple int parameters.

The String form of the date parameter is a date, followed by a space, followed by a time. You can specify a date without a time, and a time without a date, but the time zone will not be set (see "Time zones" below).

The following applies when setting a date and time from a String value:

  • The date and time components are interpreted according to the regional settings of the operating system if possible. For example, if the regional setting for dates is M/d/yy, then "3/4/05" means 4 March 2005.
  • If the date or time cannot be interpreted using the regional setting, alternate settings are tried until one works. For example, if the regional setting for dates is M/d/yy, then "13/4/05" means 13 April 2005 (using d/M/yy as the alternate setting) and "13/33/05" means 13 May 2033 (using d/yy/M as the alternate setting).
  • If the date or time cannot be interpreted using any setting, the following exception is thrown: NOTES_ERR_INVALID_DATE (4045).

The java.util.Calendar class can be used to avoid dependencies on regional settings. For example, you can use getInstance and one of the set methods to create the parameter for createDateTime.

Time zones

When you create a new DateTime object, the time zone setting in Domino® determines the TimeZone property. For example, if the code runs on a computer where the Domino® time zone is set to Eastern Standard Time, the TimeZone property of any new DateTime object is automatically set to 5. The time zone setting also affects the GMTTime and LSGMTTime properties.

If you create a date without a time component or without a date component, the time zone is invalid and the TimeZone property returns 0. In this case, both LocalTime and GMTTime return the same time value without a time zone appended. If you apply convertToZone, the time zone remains invalid and TimeZone remains 0; no error occurs.

Today, Tomorrow, and Yesterday

When you create a new DateTime object using an expression such as "Today," "Tommorow," or "Yesterday," the value of the date is determined using the current date setting in Domino®. These expressions have no effect on the time component of a DateTime object. To set a DateTime to the current date and time, specify the time after "Today" or "Yesterday" (for example, "Today 12:00:00 AM") or use setNow.

Access

To access a date-time value stored in an item in a Domino® document, use getDateTimeValue in Item.

You can get the operating system date and time separators, and time zone settings through the International class.

Example