Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Unix timestamp to Datetime in V

🎈 🎈 🎈
+1

    import time

    fn main() {
        // Unix timestamp for 2018-01-01 00:00:00
        unix_timestamp := 1514764800
    
        // Convert Unix timestamp to Date (time.Time object)
        date := time.unix(unix_timestamp)
    
        // Format the date into a readable string
        formatted_date := date.format_ss()
    
        println("Converted Date: $formatted_date")
    }            
        

Output:
Converted Date: 2021-09-27 17:16:32
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this snippet for converting a Unixt timestamp to a date using V, time.unix(unix_timestamp) converts the Unix timestamp 1632762992 to a time.Time object.
The format_ss() method formats the time.Time object as a human-readable string, showing the date and time in seconds format. The result is then printed, showing the formatted date which in the example given is 2021-09-27 17:16:32.



Other useful V date functions

Function Description Example
time.unix() Converts a Unix timestamp into a time.Time object. time.unix(1514764800) returns Time{2018, 1, 1, 0, 0, 0}
Time.unix_time() Returns the Unix timestamp for a given time.Time object. date.unix_time() returns 1531656645 (for July 15, 2018).
Time.format() Formats a time.Time object into a custom string format. date.format('yyyy-MM-dd HH:mm:ss') returns 2018-07-15 12:30:45
time.now() Returns the current date and time as a time.Time object. time.now() returns the current date and time.
time.Time{} Creates a time.Time object with the specified date and time values. time.Time{year: 2018, month: 7, day: 15, ...} creates a Time object for 2018-07-15 12:30:45.
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