Storing, creating, displaying, and converting time.
What are the results of the following operations?
01:00
Unix Time
A method to measure time as the number of seconds1 that have elapsed since midnight UTC on 1 January 1970, the Unix epoch.
| Date Time (UTC) | Unix Time |
|---|---|
| 12:01 am Jan 1, 1970 | 60 |
Unix Time
A method to measure time as the number of seconds1 that have elapsed since midnight UTC on 1 January 1970, the Unix epoch.
| Date Time (UTC) | Unix Time |
|---|---|
| 12:01 am Jan 1, 1970 | 60 |
| 12:01 am Jan 2, 1970 | 86460 |
Unix Time
A method to measure time as the number of seconds1 that have elapsed since midnight UTC on 1 January 1970, the Unix epoch.
| Date Time (UTC) | Unix Time |
|---|---|
| 12:01 am Jan 1, 1970 | 60 |
| 12:01 am Jan 2, 1970 | 86460 |
| 7 pm Oct 14, 2026 (today at noon) | 1792004400 |
Unix Time
A method to measure time as the number of seconds1 that have elapsed since midnight UTC on 1 January 1970, the Unix epoch.
| Date Time (UTC) | Unix Time |
|---|---|
| 12:01 am Jan 1, 1970 | 60 |
| 12:01 am Jan 2, 1970 | 86460 |
| 7 pm Oct 14, 2026 (today at noon) | 1792004400 |
| 5:55 pm Dec 7, 1941 | −8993325700 |
POSIXct
POSIXct (Portable Operating System Interface Calendar Time) is an atomic vector to store date-times that is built on top of a double vector.
Date
A simpler vector than POSIXct that stores date data without times. Created with as.Date().
Use as.POSIXct() to create a date-time vector from a numeric (in Unix Time) or a string in a particular format.


Use as.POSIXct() to create a date-time vector from a numeric (in Unix Time) or a string in a particular format.
[1] "1970-01-01 00:01:00 UTC"
[1] "1970-01-01 00:01:00 UTC"
lubridatelubridate() has many functions that can parse the year (y), month (m), day (d), hour (h), minute (m), and second (s) components of a date-time string.
Question: Which lubridate function parses each string?
"14 October 2026""10/14/26 9:00""2026-10-14 12:00:00"01:00
[1] "2026-10-14"
You can extract components of the date-time object using year(), month(), week(), day(), wday(), hour(), etc.
You can extract components of the date-time object using year(), month(), week(), day(), wday(), hour(), etc.
[1] Mon
Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat
You can extract components of the date-time object using year(), month(), week(), day(), wday(), hour(), etc.
[1] Monday
7 Levels: Sunday < Monday < Tuesday < Wednesday < Thursday < ... < Saturday
You can set those same components in an existing date-time object using change-in-place notation.
Question: Write the (lines) of code necessary to determine:
02:00
[1] Thursday
7 Levels: Sunday < Monday < Tuesday < Wednesday < Thursday < ... < Saturday
[1] 20638
What is the average month of these observations?
# A tibble: 6 × 2
month year
<dbl> <dbl>
1 2 2026
2 1 2026
3 2 2026
4 11 2025
5 12 2025
6 12 2025
What is the month of the average of these dates?
# A tibble: 6 × 3
month year datetime
<dbl> <dbl> <dttm>
1 2 2026 2026-02-15 00:00:00
2 1 2026 2026-01-15 00:00:00
3 2 2026 2026-02-15 00:00:00
4 11 2025 2025-11-15 00:00:00
5 12 2025 2025-12-15 00:00:00
6 12 2025 2025-12-15 00:00:00
What is the month of the average of these dates?
# A tibble: 1 × 1
avg_datetime
<dttm>
1 2026-01-04 20:00:00
What is the month of the average of these dates?
# A tibble: 1 × 2
avg_datetime mon_of_avg
<dttm> <dbl>
1 2026-01-04 20:00:00 1
A date-time is like a giant sundial: underneath it’s a single measurement, how far the shadow has travelled from a fixed origin, but we read it off the dial as hours and days. And like the dial, some parts wrap around: December sits right next to January.
