Free cookie consent management tool by TermsFeed The utcnow() function of the Python datetime class | Pythontic.com

The utcnow() function of the Python datetime class

Overview:

  • The class method utcnow() from the datetime class Python standard library returns the current time in UTC.

  • The returned datetime object does not have the tzinfo attribute set.

  • The fold attribute of DateTime object is set to zero and is not writable. Apart from the string of the form 2025-07-29 14:08:55.601448 that can be used for recreating other purposes the DateTime object returned is a timezone naive object.

Example:

# Example Python program that gets the 
# current time UTC (Coordinated Universal Time)
# using the Python class method datetime.utcnow() 

# import the datetime module
import datetime as dt

# Get UTC time using datetime class 
utcTime = dt.datetime.now()
print("UTC now:")
print(utcTime)

print("Datetime attributes:")
print("tzinfo:")
print(utcTime.tzinfo)
print("fold:")
print(utcTime.fold)

# The following line will result in an AttributeError
# stating the attribute fold is not writable.
# utcTime.fold = 1

 

Output:

UTC now:
2025-07-29 14:21:27.220166
Datetime attributes:
None
0

 


Copyright 2025 © pythontic.com