Created
October 30, 2017 13:45
-
-
Save korakot/ccd8970c5eaa3f82f8a7cc4f6c36f9ac to your computer and use it in GitHub Desktop.
Thai datetime in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime, pytz | |
tz = pytz.timezone('Asia/Bangkok') | |
def now(): | |
now1 = datetime.datetime.now(tz) | |
month_name = 'x มกราคม กุมภาพันธ์ มีนาคม เมษายน พฤษภาคม มิถุนายน กรกฎาคม สิงหาคม กันยายน ตุลาคม พฤศจิกายน ธันวาคม'.split()[now1.month] | |
thai_year = now1.year + 543 | |
time_str = now1.strftime('%H:%M:%S') | |
return "%d %s %d %s"%(now1.day, month_name, thai_year, time_str) # 30 ตุลาคม 2560 20:45:30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tz.localize(d) # change unaware→ aware
d.replace(tzinfo=None) # back to unaware
d.aztimezone(tz) # change timezone