How to Convert Date & Time Object to UNIX Timestamp in R (Example Code)

This tutorial illustrates how to transform dates and times to UNIX timestamps in R programming.

Creation of Example Data

x <- as.POSIXct("2024-05-28 11:29:47 CET")    # Examplifying POSIXct date & time
x                                             # Print POSIXct object
# [1] "2024-05-28 11:29:47 UTC"

Example: Apply as.numeric() Function to Convert a POSIXct Date & Time to a UNIX Timestamp

x_UNIX <- as.numeric(x)                       # Transform POSIXct to UNIX
x_UNIX                                        # Print UNIX timestamp
# [1] 1716895787

Related Tutorials & Further Resources

Have a look at the following R programming language tutorials. They illustrate topics such as time objects, data objects, data conversion, and dates.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed