Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programing Python Tools datetime #212

Open
junxnone opened this issue Nov 2, 2019 · 0 comments
Open

Programing Python Tools datetime #212

junxnone opened this issue Nov 2, 2019 · 0 comments

Comments

@junxnone
Copy link
Owner

junxnone commented Nov 2, 2019

datetime

获取时间

import datetime
print(datetime.datetime.now())
2022-12-28 13:17:17.400825

格式化输出

date_time = datetime.datetime.now.strftime("%m/%d/%Y, %H:%M:%S")

获取不同时区的时间

通过 pytz 设置时区

import pytz
import datetime
tz = pytz.timezone('Asia/Shanghai')

datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")

通过加减时间计算

tz_utc_8 = datetime.timezone(datetime.timedelta(hours=8))
datetime.datetime.now(tz_utc_8)
datetime.datetime.now(tz_utc_8).isoformat(' ')
'2020-03-12 13:53:24.699528+08:00'

Reference

@junxnone junxnone changed the title python datetime Programing Python datetime Dec 28, 2022
@junxnone junxnone transferred this issue from junxnone/examples Dec 28, 2022
@junxnone junxnone changed the title Programing Python datetime Programing Python Tools datetime Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant