• python_timedalte的使用


    timedalte 是datetime中的一个对象,该对象表示两个时间的差值

    构造函数:datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)
    其中参数都是可选,默认值为0

    其中:

    1 millisecond = 1000 microseconds
    1 minute = 60 seconds
    1 hour = 3600 seconds

    1 week = 7 days

    import datetime
    
    print('当前时间%s'%datetime.datetime.now())
    print('默认时间是%s'%datetime.timedelta())
    print('当前时间加3天%s'%(datetime.datetime.now()+datetime.timedelta(days=3)))
    print('当前时间减3天%s'%(datetime.datetime.now()+datetime.timedelta(days=-3)))
    print('当前时间加2周(14天)%s'%(datetime.datetime.now()+datetime.timedelta(weeks=2)))
    print('当前时间加5s%s'%(datetime.datetime.now()+datetime.timedelta(seconds=5)))
    print('当前时间加5分钟%s'%(datetime.datetime.now()+datetime.timedelta(minutes=5)))
    print('当前时间加5小时%s'%(datetime.datetime.now()+datetime.timedelta(hours=5)))
    
    
    D:studypython	estvenvScriptspython.exe D:/study/python/test/dd.py
    当前时间2019-06-14 11:58:40.512885
    默认时间是0:00:00
    当前时间加3天2019-06-17 11:58:40.512885
    当前时间减3天2019-06-11 11:58:40.513884
    当前时间加2周(14天)2019-06-28 11:58:40.513884
    当前时间加5s2019-06-14 11:58:45.513884
    当前时间加5分钟2019-06-14 12:03:40.513884
    当前时间加5小时2019-06-14 16:58:40.513884
  • 相关阅读:
    Will Go eventually replace C++ as Google hoped when Go came out?
    5G到底什么时候来,它究竟能给我们带来什么?
    eog——Eye of GNOME Image Viewer
    Appweb——Embedded Web Server
    【2017】数字重排
    【9203】众数
    【2034】四人投票
    【9204】第k小整数
    【2031】求一元三次方程的解
    iOS 7: 如何为iPhone 5s编译64位应用
  • 原文地址:https://www.cnblogs.com/xiaokuangnvhai/p/11022613.html
Copyright © 2020-2023  润新知