get system boot time in python

You can use the psutil library to get the boot time of the system.

Here's an example code snippet:

main.py
import psutil
import datetime

# Get the boot time in seconds since the epoch
boot_time = psutil.boot_time()

# Convert to a human-readable datetime object
boot_time = datetime.datetime.fromtimestamp(boot_time)

print("System boot time:", boot_time)
250 chars
11 lines

This will output the system boot time in a human-readable format like 2021-10-10 15:30:00.

gistlibby LogSnag