NotesDateTime (JavaScript™)
Represents a date and time.
Creation and usage
To create a newNotesDateTime
object,
use createDateTime in
NotesSession. You must specify a valid parameter to get a valid object.After
creating a NotesDateTime
object with createDateTime,
you can reset the date and time with setLocalTime and setLocalDate. The createDateTime method
takes a string or Date parameter. One form
of setLocalTime takes
a string parameter and another form takes a Date 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 is not 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
, then3/4/05
means4 March 2005
. - If the date or time cannot be interpreted using the regional settings,
alternate settings are tried until one works. For example, if the
regional setting for dates is
M/d/yy
, then13/4/05
means13 April 2005
(usingd/M/yy
as the alternate setting) and13/33/05
means13 May 2033
(usingd/yy/M
as the alternate setting). - If the date or time cannot be interpreted using any setting, an error occurs.
Time zones
When you create a new NotesDateTime
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 NotesDateTime
object is automatically
set to 5. The time zone setting also affects the GMTTime property.
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. 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 NotesDateTime
object using an expression
such as Today
, Tomorrow
, 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 NotesDateTime
object.
To set a NotesDateTime
to the current date and time,
specify the time after Today
(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 inNotesItem
or getItemValueDateTimeArray in NotesDocument
.You can get the operating system date and time separators, and time zone settings through the NotesInternational class.
Examples
This button creates or changes a date-time item in the current document.var doc:NotesDocument = currentDocument.getDocument();
var dt:NotesDateTime = session.createDateTime("Today 12");
dt.setNow();
doc.replaceItemValue("RecordedTime", dt);
doc.save();
var doc:NotesDocument = currentDocument.getDocument();
if (doc.hasItem("RecordedTime")) {
var dt:NotesDateTime = doc.getItemValueDateTimeArray("RecordedTime").elementAt(0);
return dt.getLocalTime() + " (" + dt.getGMTTime() + ")";
} else {
return "No recorded time"
}