Giter Club home page Giter Club logo

pytz's Introduction

pytz


https://github.com/stub42/pytz

https://launchpad.net/pytz

from datetime import datetime, timedelta
from pytz import timezone
import pytz
utc = pytz.utc
utc.zone
eastern = timezone('US/Eastern')
eastern.zone
amsterdam = timezone('Europe/Amsterdam')
fmt = '%Y-%m-%d %H:%M:%S %Z%z'


loc_dt = eastern.localize(datetime(2002, 10, 27, 6, 0, 0))
print(loc_dt.strftime(fmt))

ams_dt = loc_dt.astimezone(amsterdam)
ams_dt.strftime(fmt)

datetime(2002, 10, 27, 12, 0, 0, tzinfo=amsterdam).strftime(fmt)

datetime(2002, 10, 27, 12, 0, 0, tzinfo=pytz.utc).strftime(fmt)

utc_dt = datetime(2002, 10, 27, 6, 0, 0, tzinfo=utc)
loc_dt = utc_dt.astimezone(eastern)
loc_dt.strftime(fmt)

before = loc_dt - timedelta(minutes=10)
before.strftime(fmt)
eastern.normalize(before).strftime(fmt)
after = eastern.normalize(before + timedelta(minutes=20))
after.strftime(fmt)

dt = datetime(2002, 10, 27, 1, 30, 0)
dt1 = eastern.localize(dt, is_dst=True)
dt2 = eastern.localize(dt, is_dst=False)
dt2.strftime(fmt)

utc_dt = utc.localize(datetime.utcfromtimestamp(1143408899))
utc_dt.strftime(fmt)
au_tz = timezone('Australiz/Sydney')
au_dt = utc_dt.astimezone(au_tz)
au_dt.strftime(fmt)
utc_dt2 = au_dt.astimezone(utc)
utc_dt2.strftime(fmt)
utc_dt == utc_dt2

pytz's People

Contributors

takagotch avatar

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.