Cov txheej txheem:

Tzinfo yog dab tsi?
Tzinfo yog dab tsi?

Video: Tzinfo yog dab tsi?

Video: Tzinfo yog dab tsi?
Video: DevOps Days Kyiv 2019 -- Day 1, Ignite Talks 2024, Kaum ib hlis
Anonim

tzinfo ua yog ib qho abstract base clase, txhais tau hais tias cov chav kawm no yuav tsum tsis txhob raug instantiated ncaj qha. Koj yuav tsum tau muab ib qho kev sib koom ua ke, thiab (tsawg kawg) muab kev siv ntawm tus qauv tzinfo ua cov kev xav tau los ntawm cov txheej txheem hnub tim uas koj siv. Lub datetime module tsis muab tej qhob subclasses ntawm tzinfo ua.

Tom qab ntawd, PYTZ yog dab tsi?

pytz ua coj Olson tz database rau hauv Python. Lub tsev qiv ntawv no tso cai rau qhov tseeb thiab hla platform sijhawm suav nrog siv Python 2.4 lossis siab dua. Nws kuj tseem daws qhov teeb meem ntawm lub sijhawm tsis meej pem thaum kawg ntawm lub sijhawm txuag nruab hnub, uas koj tuaj yeem nyeem ntxiv txog hauv Python Library Reference (datetime.

Dab tsi yog qhov ua haujlwm rau offset hnub rau kev txuag nruab hnub? Txoj kev getTimezoneOffset() hauv JavaScript, hauv qhov browser, rov qab cov naj npawb ntawm feeb offset los ntawm 00: 00 lub sijhawm. Rau piv txwv , Teb Chaws Asmeskas/New_York lub sij hawm cheeb tsam nyob rau hauv Daylight Savings (DST) rov qab tus naj npawb 300.

Tib neeg kuj nug, lub sijhawm twg hauv UTC lub sijhawm?

Teb Chaws Asmeskas GMT / UTC Offsets
Lub Sijhawm Zone hauv Tebchaws Meskas UTC Offset Standard Time UTC Offset Hnub Teeb Txuag Sijhawm
Sab hnub tuaj UTC - 5 hnub UTC - 4 hnub
Central UTC – 6 h UTC - 5 hnub
Roob UTC - 7 hnub UTC - 6h * n/a rau Arizona tshwj tsis yog hauv Navajo Nation uas saib xyuas lub sijhawm txuag nruab hnub.

Kuv yuav ua li cas thiaj li tau txais lub sijhawm tam sim no hauv python?

Yog tias koj xav nrhiav lub sijhawm tam sim no ntawm qee lub sijhawm, koj tuaj yeem siv pytZ module

  1. los ntawm datetime import datetime.
  2. import pytz.
  3. tz_NY = pytz. timezone('America/New_York')
  4. datetime_NY = datetime. now(tz_NY)
  5. print("NY time:", datetime_NY.
  6. tz_London = pytz.
  7. datetime_London = hnub tim.
  8. print("London time:", datetime_London.

Pom zoo: