What am I missing, how do I get this function to work?
import dateutil.parser import datetime my_date = datetime.datetime(2000, 1, 1, 0, 0, 0, 000000, tzinfo=tzutc()) print(my_date)
Gives me the error:
NameError: name 'tzutc' is not defined
tzutc [source] This is a tzinfo object that represents the UTC time zone.
You can get the current time in a particular timezone by using the datetime module with another module called pytz . You can then check for all available timezones with the snippet below: from datetime import datetime import pytz zones = pytz. all_timezones print(zones) # Output: all timezones of the world.
The utcoffset() function is used to return a timedelta object that represents the difference between the local time and UTC time. This function is used in used in the datetime class of module datetime. Here range of the utcoffset is “timedelta(hours=24) <= offset <= timedelta(hours=24)”.
The astimezone() function is used to return a DateTime instance according to the specified time zone parameter tz. Note: The returned DateTime instance is having the new UTC offset value as per the tz parameter.
You did not import it:
from dateutil.tz import tzutc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With