Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Unix timestamp to Date in Python

🎈 🎈 🎈
+1

    import datetime
    
    # Example Unix timestamp
    timestamp = 1732134415
    
    # Convert Unix timestamp to datetime object
    date_time = datetime.datetime.fromtimestamp(timestamp)
    
    # Format the date and time in a readable format
    formatted_date = date_time.strftime('%Y-%m-%d %H:%M:%S')
    
    print("Formatted Date:", formatted_date)
        

Output:
Formatted Date: 2024-11-20 20:26:55
Example only. There may be multiple ways to perform this operation.

Code Explanation

This Python code imports the datetime module and converts a Unix timestamp (in this case 1732134415, representing seconds since January 1, 1970) into a human-readable date and time format.
The timestamp is first converted into a datetime object using datetime.datetime.fromtimestamp(), which transforms it into a local time representation. Then, the strftime() method is used to format this datetime object into a string in the format "YYYY-MM-DD HH:MM ".
Finally, the formatted date and time are printed to the console, displaying a readable version of the timestamp such as 2024-11-20 20:26:55


Other useful Python date functions

Function Description Example
time.time() Returns the current time in seconds since the Unix epoch (January 1, 1970). The result is a floating-point number representing seconds. time.time() returns 1623433347.2537498
time.sleep(seconds) Suspends (delays) execution for a specified number of seconds. time.sleep(5) pauses for 5 seconds
time.ctime([secs]) Converts a time expressed in seconds since the epoch to a string representing local time. time.ctime(1623433347) returns Tue Jun 11 17:15:47 2021
time.strftime(format[, t]) Formats a time tuple into a string based on a specified format. time.strftime('%Y-%m-%d %H:%M:%S') returns 2021-06-11 17:15:47
time.gmtime([secs]) Converts seconds since the epoch to a struct_time in UTC. time.gmtime(1623433347) returns time.struct_time(tm_year=2021, tm_mon=6, tm_mday=11, ...)
time.localtime([secs]) Converts seconds since the epoch to a struct_time in local time. time.localtime(1623433347) returns time.struct_time(tm_year=2021, tm_mon=6, tm_mday=11, ...)
time.mktime(t) Converts a struct_time representing local time to seconds since the epoch. time.mktime(time.localtime()) returns 1623433347.0
time.monotonic() Returns the value (in fractional seconds) of a monotonic clock, which cannot go backward. time.monotonic() returns 3729.8494781
time.perf_counter() Returns the value (in fractional seconds) of a performance counter, useful for benchmarking. time.perf_counter() returns 27.494923
time.process_time() Returns the CPU time (in seconds) for the current process. time.process_time() returns 0.115742
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