Skip to main content

AD

Date Time

Unix Timestamp Date Format Handling

dateString = "UNIX_TIMESTAMP_DATE_FORMAT"

datetime.datetime.fromtimestamp(int(str(dateString)[:10])).strftime('%Y-%m-%d')

The datetime module is used for manipulating dates and times.

If we want to use DateTime we need to first import in our file.

Example:

import datetime

dt = datetime.datetime.now()

print(dt)

Output: 2024-03-27 21:41:12.717541

# get the current date

currDt = datetime.date.today()

print(currDt)

Output: 2024-03-27

# get the current year

currDt = datetime.date.today()

print(currDt.year)

Output: 2024

# get the current month

print(currDt.month)

Output: 3

# get the current date only

print(currDt.day)

Output: 27

# get the current day

print(currDt.strftime("%A"))

Output: Wednesday







Comments