Datetime.tzname() method in Python

Method Name:

tzname

 

Method Signature:

tzname()

 

Method Overview:

The instance method tzname() of datetime class in Python returns the

name of the time zone associated with the datetime object.

 

Return Type:

str; Returns a python string object.

 

Example:

import datetime

 

# Mountain Time

mstTimeDelta        = datetime.timedelta(hours=7)

mstTZObject         = datetime.timezone(mstTimeDelta, name="MST")

 

mstDateTime         = datetime.datetime(2017,2,14,12,15,1,99,mstTZObject,fold=1)

 

# print time zone name

print("Name of the time zone:{}".format(mstDateTime.tzname()))

 

Output:

Name of the time zone:MST


Copyright 2024 © pythontic.com