datetime妯″潡

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了datetime妯″潡相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/style' title='style'>style   mes   rom   time()   code   pre   port   cond   mtime   

datetime妯″潡

# datetime妯″潡鍙互鐪嬫垚鏄椂闂村姞鍑忕殑妯″潡
import datetime
# 杩斿洖褰撳墠鏃堕棿
print(datetime.datetime.now())
2019-03-07 16:22:14.544130
print(datetime.date.fromtimestamp(time.time()))
2019-03-07
# 褰撳墠鏃堕棿+3澶?/span>
print(datetime.datetime.now() + datetime.timedelta(3))
2019-03-10 16:22:14.560599
# 褰撳墠鏃堕棿-3澶?/span>
print(datetime.datetime.now() + datetime.timedelta(-3))
2019-03-04 16:22:14.568473
# 褰撳墠鏃堕棿-3灏忔椂
print(datetime.datetime.now() + datetime.timedelta(hours=3))
2019-03-07 19:22:14.575881
# 褰撳墠鏃堕棿+30鍒嗛挓
print(datetime.datetime.now() + datetime.timedelta(minutes=30))
2019-03-07 16:52:14.585432
# 鏃堕棿鏇挎崲
c_time = datetime.datetime.now()
print(c_time.replace(minute=20, hour=5, second=13))
2019-03-07 05:20:13.595493

以上是关于datetime妯″潡的主要内容,如果未能解决你的问题,请参考以下文章

os妯″潡

Ansible甯哥敤妯″潡-yum妯″潡

re 妯″潡銆乼yping 妯″潡銆乧ollections 妯″潡

sys 妯″潡

鏃堕棿time妯″潡

python瀛︿範--bisect妯″潡