Dates, Times & Randomness
Time zones: TimeZones.jl (ZonedDateTime(now(), tz"Europe/Oslo")).
21.1 Dates
Time zones: TimeZones.jl (ZonedDateTime(now(), tz"Europe/Oslo")).
using Dates
today(), now(), now(UTC)
d = Date(2026, 10, 25)
dt = DateTime(2026, 10, 25, 14, 30)
Date("25/10/2026", dateformat"dd/mm/yyyy")
Dates.format(d, "E, d U yyyy") # "Sunday, 25 October 2026"
year(d), month(d), day(d), dayofweek(d), dayname(d), dayofyear(d), week(d), quarterofyear(d)
d + Day(30), d + Month(1), d - Year(1)
Date(2027, 1, 1) - d # 68 days
Dates.value(Date(2027, 1, 1) - d) # 68
collect(d:Month(1):Date(2027, 3, 1))
firstdayofmonth(d), lastdayofweek(d), tonext(d, Friday)
Dates.datetime2unix(now()), unix2datetime(1.7e9)
Time(9, 30), Millisecond(1500) |> Dates.canonicalize21.2 Random numbers
using Random
Random.seed!(42) # reproducibility
rand(), rand(1:6), rand(3), rand(Float32, 2, 2), randn(5), randexp(3)
rng = MersenneTwister(1); rand(rng, 1:10)
rng = Xoshiro(123) # default RNG family since 1.7
shuffle([1, 2, 3]), shuffle!(v), randperm(5), randsubseq(1:100, 0.1)
rand(["a", "b", "c"]), randstring(8)
using StatsBase
sample(1:10, 3; replace=false), sample(["a", "b"], Weights([0.9, 0.1]), 10)
using Distributions
d = Normal(100, 15); rand(d, 5); pdf(d, 100); cdf(d, 130); quantile(d, 0.975); mean(d)
fit(Normal, randn(1000))