This page is for an old version of Hexaly Optimizer. We recommend that you update your version and read the documentation for the latest stable release.

Date/time module

Note

To use the methods listed below in your program, you have to put a special import statement at the begining of your LSP file: use datetime;

Module functions

datetime.now()

Returns a new DateTime object that is set to the current date and time on this computer expressed as local time.

Return type:

DateTime

datetime.utcNow()

Returns a new DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).

Return type:

DateTime

datetime.today()

Returns a new DateTime that is set to today’s date, with the time component set to 00:00:00.0.

Return type:

DateTime

datetime.isLeapYear(year)

Returns true if the year, given as an integer, is a leap year.

Return type:

bool

datetime.date(year, month, day)

Returns a new DateTime object that is set to the given year, month (1-12) and day (1-31). The time component of the datetime object will be set to 00:00:00.0.

Return type:

DateTime

datetime.date(year, month, day, hour, minute, second)

Returns a new DateTime object that is set to the given year, month (1-12), day (1-31), hour (0-23), minute (0-59) and second (0-59).

Return type:

DateTime

datetime.span(nbHours, nbMinutes, nbSeconds)
datetime.span(nbDays, nbHours, nbMinutes, nbSeconds)
datetime.span(nbDays, nbHours, nbMinutes, nbSeconds, nbMilliseconds)

DateTime

Represents an instant in time, expressed as a date and time of day.

class DateTime
date

Returns the date component of the current datetime instance. The returned object has the same date as this instance, and its time component set to midnight (00:00:00.0).

Return type:

DateTime

year

Gets the year component of the date represented by this datetime instance.

Return type:

int

month

Gets the month component of the date represented by this datetime instance. The month component is expressed as an integer between 1 and 12.

Return type:

int

day

Gets the day of the month represented by this datetime instance. The day of the month is expressed as an integer between 1 and 31.

Return type:

int

dayOfWeek

Gets the day of the week represented by this datetime instance. The day of the week is expressed as an integer between 1 and 7 where 1 represents Monday and 7 represents Sunday (according to ISO-8601 standard).

Return type:

int

dayOfYear

Gets the day of the year represented by this datetime instance. The day of the year is expressed as an integer between 1 and 366.

Return type:

int

hour

Gets the hour component of the date represented by this datetime instance. The hour component is expressed as an integer between 0 and 23.

Return type:

int

minute

Gets the minute component of the date represented by this datetime instance. The minute component is expressed as an integer between 0 and 59.

Return type:

int

second

Gets the second component of the date represented by this datetime instance. The second component is expressed as an integer between 0 and 59.

Return type:

int

millisecond

Gets the millisecond component of the date represented by this datetime instance. The millisecond component is expressed as an integer between 0 and 999.

Return type:

int

add(timespan)
addYears(nbYears)
addMonths(nbMonths)
addDays(nbDays)
addHours(nbHours)
addMinutes(nbMinutes)
addSeconds(nbSeconds)
addMilliseconds(nbMillis)
format(fmt)

TimeSpan

class TimeSpan
days
hours
minutes
seconds
milliseconds
totalDays
totalHours
totalMinutes
totalSeconds
totalMilliseconds
add(timespan)
addDays(nbDays)
addHours(nbHours)
addMinutes(nbMinutes)
addSeconds(nbSeconds)
addMilliseconds(nbMillis)

Date format

The following table describes the custom date and time format specifiers that can be used with the DateTime.format() function.

Format specifier

Description

y

The year, from 0 to 99.

yy

The year with leading zero (2 digits) from 00 to 99

yyy

The year, with a minimum of three digits. from 000 to 9999.

yyyy

The year as a four-digit number.

M

The month, from 1 through 12.

MM

The month with leading zero (2 digits) from 01 through 12.

MMM

The abbreviated name of the day of the month (Jan, Feb, Mar, Apr, May, June, July, Aug, Sept, Oct, Nov, Dec).

MMMM

The full name of the month (January, February, March, April, May, June, July, August, September, October, November, December).

d

The day of the month, from 1 through 31

dd

The day of the month with leading zero (2 digits) from 01 through 31.

ddd

The abbreviated name of the day of the week. (Mon, Tue, Wed, Thu, Fri, Sat, Sun)

dddd

The full name of the day of the week (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday).

H

24-hour format of the hour, from 0 to 23.

HH

24-hour format of the hour with leading zero (2 digits) from 00 through 23.

h

12-hour format of the hour, from 1 to 12.

hh

12-hour format of the hour with leading zero (2 digits) from 01 through 12.

m

The minute, from 0 to 59.

mm

The minute with leading zero (2 digits) from 00 through 59.

s

The second, from 0 to 59.

ss

The second with leading zero (2 digits) from 00 through 59.

f

The tenths of a second from 0 to 9

ff

The hundredths of a second with leading zero (2 digits) from 00 to 99

fff

The milliseconds with leading zeros (3 digits) from 000 to 999

g, gg

The period or era (A.D. or B.C.)

t

The first character of AM/PM (A or P)

tt

Ante meridiem and Post meridiem (AM or PM)

\

Escape character. Used to introduce escape sequence.

other character

The character is copied unchanged.