Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Datetime to Unix timestamp in Julia

🎈 🎈 🎈
+1

    using Dates

    date_time = DateTime(2004, 8, 10, 5, 20, 00)
    unix_timestamp = datetime2unix(date_time)
    
    println("Unix Timestamp: ", unix_timestamp)            
        

Output:
Unix Timestamp: 1092115200
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this example of date to Unix timestamp conversion in Julia, the DateTime() function creates a DateTime object representing '2004-08-10 05:20:00'.
The datetime2unix() function converts this date and time into its corresponding Unix timestamp, which is '1092115200'.



Other useful Julia date functions

Function Description Example
Date() Creates a Date object from year, month, and day. Date(2022, 5, 15) returns 2022-05-15
DateTime() Creates a DateTime object from year, month, day, hour, minute, and second. DateTime(2022, 5, 15, 8, 30, 45) returns 2022-05-15T08:10:45
now() Returns the current date and time as a DateTime object. now() returns 2024-08-28T12:34:56
today() Returns the current date as a Date object. today() returns 2024-08-28
unix2datetime() Converts a Unix timestamp to a DateTime object. unix2datetime(1652602245) returns 2022-05-15T08:10:45
datetime2unix() Converts a DateTime object to a Unix timestamp. datetime2unix(DateTime(2022, 5, 15, 8, 30, 45)) returns 1652602245
format() Formats a Date or DateTime object as a string according to the provided format string. Dates.format(Date(2022, 5, 15), "yyyy-mm-dd") returns 2022-05-15
Day() Represents a day period, which can be added or subtracted from dates. Date(2022, 5, 15) + Day(5) returns 2022-05-20
Month() Represents a month period, which can be added or subtracted from dates. Date(2022, 5, 15) + Month(2) returns 2022-07-15
Year() Represents a year period, which can be added or subtracted from dates. Date(2022, 5, 15) + Year(1) returns 2023-05-15
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