DateTime, TimeDelta, strftime in Python

Devcult - 6G and Satellites
1 min readMay 14, 2019

--

The datetime classes in Python are categorized into main 5 classes.

date — manipulate just date (Month, day, year)

time — Time independent of the day (Hour, minute, second, microsecond)

datetime — Combination of time and date (Month, day, year, hour, second, microsecond)

timedelta — A duration of time used for manipulating dates

tzinfo — An abstract class for dealing with time zones.

datetime class

datetime.date.today()

datetime.date.today.day()

datetime.date.today.month()

datetime.date.today.year()

datetime.date.today.weekday()

datetime.datetime.now() #date

datetime.time(datetime.now()) #time

strftime, datetime, time classes are present in this.

  1. datetime.strftime converts datetime object to a string
  2. datetime.strptime converts string to a datetime object

Use datetime.strptime to check if date is present in a string

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Devcult - 6G and Satellites
Devcult - 6G and Satellites

No responses yet

Write a response