Skip to content

Datetime

It generates various random dates.

Example

Local date

;; Generate a random LocalDate
(def random-date (random-local-date))
(println "Random LocalDate:" random-date)

Local time

;; Generate a random LocalTime
(def random-time (random-local-time))
(println "Random LocalTime:" random-time)

Local date time

;; Generate a random LocalDateTime
(def random-date-time (random-local-date-time))
(println "Random LocalDateTime:" random-date-time)

Zone id

;; Generate a random ZoneId
(def random-zone (random-zone-id))
(println "Random ZoneId:" random-zone)

Zone date time

;; Generate a random ZonedDateTime
(def random-zoned-date-time (random-zoned-date-time))
(println "Random ZonedDateTime:" random-zoned-date-time)

Date between two dates in string format

;; Generate a random date between two given dates (string format)
(def random-date-str (random-date-between-strings "2020-01-01" "2023-01-01"))
(println "Random Date between 2020-01-01 and 2023-01-01:" random-date-str)

Date between two local dates

;; Generate a random date between two given LocalDate objects
(def start-date (LocalDate/of 2020 1 1))
(def end-date (LocalDate/of 2023 1 1))
(def random-date-range (random-date-between start-date end-date))
(println "Random Date between given LocalDate objects:" random-date-range)

Format date/time

;; Format a given date/time object
(def formatted-date (format-date random-date-time "dd-MM-yyyy"))
(println "Formatted LocalDateTime:" formatted-date)

Format a random local date

;; Generate and format a random LocalDate
(def formatted-random-date (formatted-random-local-date "dd/MM/yyyy"))
(println "Formatted Random LocalDate:" formatted-random-date)

Format a random local time

;; Generate and format a random LocalTime
(def formatted-random-time (formatted-random-local-time "HH:mm"))
(println "Formatted Random LocalTime:" formatted-random-time)

Format a random local date time

;; Generate and format a random LocalDateTime
(def formatted-random-date-time (formatted-random-local-date-time "yyyy-MM-dd HH:mm:ss"))
(println "Formatted Random LocalDateTime:" formatted-random-date-time)

Format a random zoned date time

;; Generate and format a random ZonedDateTime
(def formatted-random-zoned-time (formatted-random-zoned-date-time "yyyy-MM-dd HH:mm:ss Z"))
(println "Formatted Random ZonedDateTime:" formatted-random-zoned-time)

Random weekday name

;; Generate a random weekday name in specified language
(def random-weekday (random-weekday-name :es))
(println "Random Weekday (Spanish):" random-weekday)

Random month name

;; Generate a random month name in specified language
(def random-month (random-month-name :fr))
(println "Random Month (French):" random-month)

Random year

;; Generate a random year
(def random-year (random-year 2000 2025))
(println "Random Year between 2000 and 2025:" random-year)

Random hour

;; Generate a random hour with AM
(def random-hour-am (random-hour "AM"))
(println "Random Hour (AM):" random-hour-am)