Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

เมธอด time.tzset() ใน Python ทำอะไร

time.tzset() รีเซ็ต Time Conversion Rules ที่ Library Routines ใช้ ใช้ Environment Variable TZ กำหนดวิธีการแปลง ยังตั้งค่า Variables:

  • tzname (จาก TZ)
  • timezone (Non-DST Seconds West of UTC)
  • altzone (DST Seconds West of UTC)
  • daylight (0 = ไม่มี DST Rules, Non-zero = มี DST)

ฟังก์ชันนี้ใช้ได้เฉพาะ Unix Format มาตรฐานของ TZ:

std offset [dst [offset [,start[/time], end[/time]]]]

ตัวอย่าง

import time, os

os.environ['TZ'] = 'EST+05EDT,M4.1.0,M10.5.0'
time.tzset()
print(time.strftime('%X %x %Z'))

os.environ['TZ'] = 'AEST-10AEDT-11,M10.5.0,M3.5.0'
time.tzset()
print(time.strftime('%X %x %Z'))

ผลลัพธ์

13:00:40 02/17/09 EST
05:00:40 02/18/09 AEDT