Skip to main content

Command Palette

Search for a command to run...

how to get the current time in python

Updated
•1 min read•View as Markdown
D

Owner of howtouselinux.com. I work as a Linux engineer for over 20 years. Now I am a technical blogger and Software Engineer. I enjoy sharing learning and contributing to open-source.

Get current time with python time module

import time
print(time.time())
1586813438.419919
print(time.ctime())
Mon Apr 13 23:30:38 2020

Get current time with python datetime module

import datetime
print(datetime.datetime.now())
2021-11-13 23:30:38.419951
print(datetime.date.today())
2021-11-13

Get current time with python os module

import os
os.system('date')
Sun Feb 20 10:12:36 UTC 2022
os.system('date +"%Y-%m-%d %H:%M:%S"')
2022-02-20 10:30:09

3 ways to get the current time in python

10 tips to use Python OS module

More from this blog

Linux Skills

26 posts