Date - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Date

 

Calling Sequence

Parameters

Options

Description

Methods

Examples

Compatibility

Calling Sequence

Date()

Date( d )

Date( t )

Date( year, month, day, hour, minute, second, millisecond )

Parameters

d

-

Date; a Date object

t

-

Time ; a Time object

year

-

integer; the year (required)

month

-

integer; the number (1..12) of a month

day

-

integer; the number of a day within the month month

hour

-

integer; the hour (0..24) of the day

minute

-

integer; the minute within the hour

second

-

numeric; the second within the minute (may be fractional)

millisecond

-

numeric; the millisecond within the second

Options

• 

timezone : string; the name of a time zone

Description

• 

The Date object represents a particular date and time in the Gregorian calendar. It represents a particular "view" of the a system UTC time, as represented by a Time object associated to the system UTC clock.

• 

You can create a Date object by calling the Date constructor in several different ways.

• 

Called without arguments, the Date() command returns the current date (and time of day) as reported by the system clock.

• 

You can also pass an explicit UTC Time object t by calling the Date constructor in the form Date( t ).  This produces a Date object that represents the Time object t.

• 

A Date object d can be passed to the Date constructor in the form Date( d ), producing a new Date object that represents the same moment in time as the original Date object d.  This is most useful when used in conjunction with the timezone= option to convert between different time zones.

• 

The Date constructor also takes specific components: year, month, day, hour, minute, second and millisecond. These must be passed in the stated order, but all components after the year are optional in the sense that any initial sub-sequence of these may be passed with the values for omitted components being set to their default values. The default values for components after the year are all 0, except for hour, for which the default values is 12 (representing noon). However, you cannot specify any particular component without specifying all the components before it in the sequence. For example, to pass the hour component, you must also specify the year, month and day components (in that order) first.

• 

The year value year must be in the range −9223372036854775808year9223372036854775807 on 64-bit platforms. On 32-bit platforms, the year is limited to the range −4294967296year4294967295.

Methods

• 

Date objects support a number of methods.

Year  the year of the Date object

Month  the (numeric) month within the year

DayOfMonth  the (numeric) day of the month

HourOfDay  the hour of the day

Minute  the minute within the hour

Second  the seconds within the minute

TimeZone  the time zone of the Date object (by default, "UTC")

Precision  the precision of the Date object; normally the precision of the underlying Clock

• 

The Year( d ) command returns the (integer) year of the Date object d.

• 

The Month( d ) command returns the numeric month of the Date object d. This is an integer in the range 1 .. 12, with 1 denoting January, 2 denoting February, and so on.

• 

The (integer) day of the month of the Date object d is returned by the command DayOfMonth( d ).  This is a positive integer, no larger than the last day of the month represented by d.

• 

The HourOfDay( d ) command returns an integer in the range 0 .. 24 denoting the hour of the day represented by d (that is, a 24-hour clock). Note that an hour equal to 24 is equivalent to the 0th hour of the next day.

• 

The minute of the hour represented by d is returned by the command Minute( d ).

• 

The Second( d ) command returns the number of seconds after the minute of d.

• 

The default time zone of a Date object is the local time zone. The TimeZone( d ) command returns the time zone of d, which may be set explicitly via the timezone = T option.

• 

Since a Date object is just a particular view onto a moment in time, represented by a Time object stored within the Date, it has an associated precision, which is equal to the precision of the underlying clock. In this case, the clock is the SystemUTCClock. The Precision( d ) command returns the precision associated with the Date object d.

• 

In addition to the command-like methods listed above, arithmetic with Date objects is supported, as are comparisons using the operators < and <=.

• 

To compute the length of time between two dates represented by Date objects d1 and d2, use the expression d1 - d2. More generally, a rational combination of Date objects with coefficients that sum to 0 returns a unit expression of the time dimension.

• 

Similarly, the midpoint between two Date objects d1 and d2 can be computed using the expression (d1 + d2) / 2. Again, more general rational combinations of Date objects with coefficient summing to 1 return a new Date object representing a generalized "average" of those dates.

• 

Other combinations of Date objects return unevaluated.

• 

Note that leap seconds are ignored in all date and time arithmetic.

Examples

Create the current date in the default time zone.

todayDate

today<Date: 2024-03-01T04:27:09.383 GMT>

(1)

Extract various components of the object.

Yeartoday

2024

(2)

Monthtoday

3

(3)

Minutetoday

27

(4)

Create the current date in the local time zone.

todayDateNowSystemUTCClock&comma;timezone=Calendar:-HostTimeZone

today<Date: 2024-03-01T04:27:09 GMT>

(5)

Create a specific date representing 3:42am on July 1, 1967.

dDate1967&comma;7&comma;1&comma;3&comma;42

d<Date: 1967-07-01T03:42:00 GMT>

(6)

How long has it been since that moment?

todayd

1788309909401ms

(7)

Midnight (or any moment before 1am) can be specified either as the 24th hour of one day, or the 0th hour of the next day.

d1Date1999&comma;3&comma;14&comma;24

d1<Date: 1999-03-15T00:00:00 GMT>

(8)

d2Date1999&comma;3&comma;15&comma;0

d2<Date: 1999-03-15 GMT>

(9)

d1d2

0

(10)

To compute the length of the Second World War (taken from the invasion of Poland, at 4:45am on Sept. 1, 1939 to the formal surrender of Japan at about 9am on Sept. 2, 1945), construct the Date objects corresponding to the beginning and end events of the war, and subtract.

d1Date1939&comma;9&comma;1&comma;4&comma;45&comma;timezone=Europe/Berlin

d1<Date: 1939-09-01T04:45:00 Germany Time>

(11)

d2Date1945&comma;9&comma;2&comma;9&comma;timezone=Asia/Tokyo

d2<Date: 1945-09-02T09:00:00 Japan Time>

(12)

The result is in milliseconds, since that is the precision of the UTC clock.

tdiffd2d1

tdiff189461700000ms

(13)

Use the convert command with the units option to convert the result to a more convenient form.

converttdiff&comma;units&comma;days

7017132d

(14)

converttdiff&comma;units&comma;years

6.003807364yr

(15)

Compatibility

• 

The Date command was introduced in Maple 2018.

• 

For more information on Maple 2018 changes, see Updates in Maple 2018.

See Also

Calendar

Time

Today