Code Monkey home page Code Monkey logo

Comments (4)

alanhamlett avatar alanhamlett commented on September 13, 2024 2

Pytz doesn't work with DST and datetime.replace(tzinfo=<timezone>).

Here's how to get the current time in Los Angeles:

import datetime from datetime
import pytz

pdt = pytz.timezone('America/Los_Angeles')
now_utc = datetime.utcnow().replace(tzinfo=pytz.utc)
now_pdt = now_utc.astimezone(pdt)

More info in this Stackoverflow answer and the pytz docs.

from pytz.

Yang-z avatar Yang-z commented on September 13, 2024 1

OK,
tz_LA = dateutil.tz.gettz('America/Los_Angeles')
works as expected.
I guess pytz provides in-normalized tzinfo due to some advanced usages.

from pytz.

durack1 avatar durack1 commented on September 13, 2024

@stub42 I'm also getting the same behavior with 2018.4

from pytz.

Yang-z avatar Yang-z commented on September 13, 2024

Giving,

time_str = "20190101 120000”
timezone = pytz.timezone('America/Los_Angeles')
datetime = ?

How to convert to a datetime, when the string itself is a local time of i.e. Los Angeles?
I'm quite struggling with this, because datetime.replace(tzinfo=) would cause the problem as mentioned above.

from pytz.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.