Skip to content

Latest commit

 

History

History
85 lines (73 loc) · 2.56 KB

datetimes.md

File metadata and controls

85 lines (73 loc) · 2.56 KB

Datetimes

Datetimes is another primitive data type of RainLisp. Unlike the other primitive types we have seen so far, a datetime does not have a literal representation. You can make one and handle it with primitive procedures.

Let's create a datetime that represents the last day of 2023.

(make-date 2023 12 31)

-> 2023-12-31 00:00:00.000

We specified the year, followed by the month, followed by the day. Note that we did not set a time.

Now, let's specify a datetime with a time too.

(make-datetime 2023 12 31 21 30 45 999)

-> 2023-12-31 21:30:45.999

This time, after the day, we specified the hour, minute, second and millisecond in that order.

There are also accessor procedures that, given a datetime, let you access its constituent parts.

Let's try them with the current datetime returned by calling the primitive procedure now.

(year (now))
(month (now))
(day (now))
(hour (now))
(minute (now))
(second (now))
(millisecond (now))

->

2023
4
23
21
3
19
583

There are many operations that help you work with datetimes:

Well done! You have learned about RainLisp's primitive types. Now, it's time to move on and learn about the essence of the language, starting with variables.