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:
- <
- <=
- =
- >
- >=
- add-days
- add-hours
- add-milliseconds
- add-minutes
- add-months
- add-seconds
- add-years
- datetime-to-string
- day
- days-diff
- hour
- hours-diff
- make-date
- make-datetime
- millisecond
- milliseconds-diff
- minute
- minutes-diff
- month
- now
- parse-datetime
- second
- seconds-diff
- to-local
- to-utc
- utc-now
- utc?
- year
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.