Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python datetime localization

Tags:

python

What do I need to do (modules to load, locale methods to invoke, etc.) so that when I call:

datetime.date(2009,1,16).strftime("%A %Y-%b-%d")

instead of getting:

Out[20]: 'Friday 2009-Jan-16'

i get spanish/french/german/... output

Out[20]: 'Viernes 2009-Ene-16'

without having to change my whole operating system's locale (i.e. just use python calls to dynamically set the locale and keep the changes scoped within my app)

Thanks.

like image 547
jd. Avatar asked Jan 19 '10 03:01

jd.


People also ask

Does datetime have timezone Python?

One of the modules that helps you work with date and time in Python is datetime . With the datetime module, you can get the current date and time, or the current date and time in a particular time zone.

What does pytz UTC localize do?

localize() pytz. localize() is useful for making a naive timezone aware. it is useful when a front-end client sends a datetime to the backend to be treated as a particular timezone (usually UTC).

How do you add timezone in Python?

You can also use the pytz module to create timezone-aware objects. For this, we will store the current date and time in a new variable using the datetime. now() function of datetime module and then we will add the timezone using timezone function of pytz module.

How does Python handle time zones?

The parameter pytz. timezone allows us to specify the timezone information as a string. We can pass in any available timezone and will get the current date time of that timezone, and it will also print the offset with respect to the UTC. i.e., the difference between UTC timezone(+00:00) and the specified time zone.


1 Answers

locale.setlocale()

like image 132
Ignacio Vazquez-Abrams Avatar answered Oct 22 '22 20:10

Ignacio Vazquez-Abrams