Skip to content

Instantly share code, notes, and snippets.

@tcpdump-examples
Created March 6, 2022 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcpdump-examples/fd08b1c06c9b7350b65eab2f5e62c793 to your computer and use it in GitHub Desktop.
Save tcpdump-examples/fd08b1c06c9b7350b65eab2f5e62c793 to your computer and use it in GitHub Desktop.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment