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;

Functions

datetime.now()

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

datetime.utcNow()

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

datetime.today()

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

datetime.isLeapYear(year)

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

datetime.date(year, month, day)

Returns a new datetime 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.

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

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

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

Datetime

type datetime
date
year
month
day
dayOfWeek
dayOfYear
hour
minute
second
millisecond
add(timespan)
addYears(nbYears)
addMonths(nbMonths)
addDays(nbDays)
addHours(nbHours)
addMinutes(nbMinutes)
addSeconds(nbSeconds)
addMilliseconds(nbMillis)
format(fmt)

Timespan

type 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.