python时间模块 dir(time)_Python内置模块-time-date time

1、路径

dir()的__file__ 方法

os.path.dirname(__file__)  #获取当前路径上一层

os.path.abspath(__file__)  #获取当前绝对路径

sys.path.append()  #增加到环境变量

2、time模块

3、datetime

t = datetime.datetime.now() #返回当前时间

t.timestamp()  #时间戳

t.today() #返回时间元祖 datetime.datetime(2018, 7, 29, 23, 48, 29, 860069)

t.year  #返回年 2018

t.timetuple()  #返回时间对象

datetime.date.fromtimestamp(123123123) #把一个时间戳专为datetime时间类型 datetime.date(1973, 11, 26)

t1 = datetime.timedelta(hours=3) #时间运算,括号参数默认年,year=4 hours=4

t-t1  # 回到三小时前

时间替换

>>> d = datetime.datetime.now()

>>> d

datetime.datetime(2018, 7, 29, 23, 56, 46, 605826)

>>> d.replace(year=1988,month=2,day=10)

datetime.datetime(1988, 2, 10, 23, 56, 46, 605826)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值