Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is django.utils.datetime_safe and should I use it instead of standard datetime?

What are the differences? Is it safer to use datetime_safe? I can't find any documentation on this class.

like image 592
Lord_JABA Avatar asked Feb 24 '14 15:02

Lord_JABA


People also ask

What are Django utils?

Django Utils is a collection of small Django helper functions and classes which make common patterns shorter and easier.

How does Django use timezone now?

The solution to this problem is to use UTC in the code and use local time only when interacting with end users. Time zone support is disabled by default. To enable it, set USE_TZ = True in your settings file. In Django 5.0, time zone support will be enabled by default.

How do I change the time in Django?

You only need to configure a few things in your Django application's settings.py to set the timezone. By default, the Time zone is UTC, and USE_TZ is set to True, which ensures that using a datetime. now() function in your Django application creates time in UTC.


1 Answers

The difference is noted in the source code for datetime_safe:

# Python's datetime strftime doesn't handle dates before 1900.
# These classes override date and datetime to support the formatting of a date
# through its full "proleptic Gregorian" date range.

Huh.

like image 128
slezica Avatar answered Oct 20 '22 23:10

slezica