Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Datetime to Unix timestamp in Tcl

🎈 🎈 🎈
+1

    # Human-readable date (2026-10-24 09:46:40)
    set date_string "2026-10-24 09:46:40"
    
    # Convert Date to Unix timestamp
    set unix_timestamp [clock scan $date_string -format "%Y-%m-%d %H:%M:%S" -gmt true]
    
    # Output the Unix timestamp
    puts "Unix Timestamp: $unix_timestamp"            
        

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

Code Explanation

In this TCL snippet clock scan $date_string takes the date string '2026-10-24 09:46:40' and converts it to a Unix timestamp. The -format "%Y-%m-%d %H:%M:%S" part tells TCL the format of the input string while -gmt true ensures that the date is interpreted in GMT (UTC).



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