Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Convert Datetime to Unix Timestamp in R

How to convert Datetime to Unix timestamp in R

🎈 🎈 🎈
+1

    date <- as.POSIXct("2013-05-19 12:34:59", tz="UTC")
    unix_timestamp <- as.numeric(date)
    print(unix_timestamp)            
        

Output:
1368966899
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this R second example, a specific date ("2013-05-19 12:34:59") is converted to a Unix timestamp using as.POSIXct() to create a date-time object and as.numeric() to convert it to the number of seconds since the Unix epoch.



Other useful R date functions

Function Description Example
Sys.Date() Returns the current date. Sys.Date() returns 2024-08-28
Sys.time() Returns the current date and time as a POSIXct object. Sys.time() returns 2024-08-28 12:34:56
as.Date() Converts a character string to a Date object. as.Date('2024-08-28') returns 2024-08-28
as.POSIXct() Converts a date-time string or object to a POSIXct object, which represents the date and time in seconds since the Unix epoch. as.POSIXct('2024-08-28 12:34:56') returns 2024-08-28 12:34:56
as.POSIXlt() Converts a date-time string or object to a POSIXlt object, which stores date-time components as a list. as.POSIXlt('2024-08-28 12:34:56') returns a list with date-time components.
format() Formats a date or date-time object according to a specified format string. format(Sys.Date(), '%Y-%m-%d') returns 2024-08-28
difftime() Calculates the difference between two dates or date-time objects. difftime(Sys.time(), as.POSIXct('2024-08-28 12:00:00')) returns 0.5 hours
strptime() Parses a date-time string according to a specified format and returns a POSIXlt object. strptime('2024-08-28 12:34:56', '%Y-%m-%d %H:%M:%S') returns a POSIXlt object.
seq.Date() Generates a sequence of dates. seq.Date(from=as.Date('2024-08-28'), by='1 day', length.out=3) returns 2024-08-28, 2024-08-29, 2024-08-30
julian() Calculates the Julian date (days since origin) for a Date or POSIXct object. julian(as.Date('2024-08-28')) returns 20143 days since origin.
Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder