Python datetime 时间的计算

import datetime
print(1,datetime.date.today())
print(2,datetime.datetime.today())
print(3,datetime.datetime.now())
print(4,datetime.datetime.today().strftime('%Y-%m-%d'))
print(5,datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S'))
print(6,datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S %A'))
print(7,datetime.datetime.today().strftime('%Y'))
print(8,datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S %a'))
print(9,datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S %a %b %B'))
#倒计时
day20 = datetime.datetime.strptime('2020-07-01 0:0:0','%Y-%m-%d %H:%M:%S')
now = datetime.datetime.today()
delta = day20 - now
print(10,"时间差值:",delta)
day = delta.days
hour = int(delta.seconds/60/60)
minute = int((delta.seconds-hour*60*60)/60)
second = delta.seconds-hour*60*60-minute*60
print(11,day,hour,minute,second)
#计算过去或者未来
print(12,datetime.datetime.now()+datetime.timedelta(days=5))
print(13,datetime.datetime.now()+datetime.timedelta(hours=5*24))
print(14,(datetime.datetime.now()-datetime.timedelta(hours=24)).strftime('%Y-%m-%d'))

1 2019-09-11
2 2019-09-11 15:59:57.718880
3 2019-09-11 15:59:57.718880
4 2019-09-11
5 2019-09-11 15:59:57
6 2019-09-11 15:59:57 Wednesday
7 2019
8 2019-09-11 15:59:57 Wed
9 2019-09-11 15:59:57 Wed Sep September
10 时间差值: 293 days, 8:00:02.263129
11 293 8 0 2
12 2019-09-16 15:59:57.736870
13 2019-09-16 15:59:57.736870
14 2019-09-10

 

a = round(3.745,2)
print(a)
a = round(3.745)
print(a)

3.75
4

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值