Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Unix timestamp to Datetime in Tcl

🎈 🎈 🎈
+1

    set unix_timestamp 1472832928
    
    # Convert Unix timestamp to Date
    set formatted_date [clock format $unix_timestamp -format "%Y-%m-%d %H:%M:%S" -gmt true]
    
    # Output the formatted date
    puts "Converted Date: $formatted_date"            
        

Output:
Converted Date: 2016-09-02 16:15:28
Example only. There may be multiple ways to perform this operation.

Code Explanation

When using TCL to convert Unix timestamp clock format $unix_timestamp takes the Unix timestamp 1472832928 and converts it into a human-readable format. -format "%Y-%m-%d %H:%M:%S" specifies the format for the date (year-month-day hour:minute) and -gmt true ensures the output is in GMT (UTC) time.


Other useful Tcl date functions

Command Description Example
clock format Formats a Unix timestamp into a human-readable date. clock format 1514764800 -format "%Y-%m-%d %H:%M:%S" returns 2018-01-01 00:00:00
clock scan Parses a date string and returns the Unix timestamp. clock scan "2018-07-15 12:30:45" -format "%Y-%m-%d %H:%M:%S" returns 1531656645
clock seconds Returns the current Unix timestamp. clock seconds returns the current Unix timestamp.
-gmt Used with clock format or clock scan to specify UTC (GMT) time. clock format 1514764800 -gmt true formats the date in UTC.
-format Specifies the format for parsing or displaying the date. clock format 1514764800 -format "%Y-%m-%d %H:%M:%S" formats as 2018-01-01 00:00:00.
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