Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use tzutc()

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 
like image 803
Aminoff Avatar asked Jun 19 '17 08:06

Aminoff


People also ask

What is Tzutc?

tzutc [source] This is a tzinfo object that represents the UTC time zone.

How do I get local timezone in python?

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.

How do I set timezone offset in Python?

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)”.

What is Astimezone in Python?

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.


1 Answers

You did not import it:

from dateutil.tz import tzutc 
like image 152
jojomojo Avatar answered Sep 19 '22 14:09

jojomojo