zoukankan      html  css  js  c++  java
  • python 时间转换

    #
    # import datetime
    # from datetime import datetime
    # import time
    #
    # now_time = datetime.now()
    # # now:2019-07-31 15:05:54.306301
    # print('now:{0}'.format(datetime.now()))
    #
    # # 当前的日期
    # # now day:2019-07-31
    # print('now day:{0}'.format(now_time.date()))
    #
    # # 当前的时间
    # # now time:15:07:54.550967
    # print('now time:{0}'.format(now_time.time()))
    #
    # # 当前年份
    # # now year:2019
    # print('now year:{0}'.format(now_time.year))
    #
    # # 当前月份
    # # now month:7
    # print('now month:{0}'.format(now_time.month))
    #
    # # 当前日期
    # # now day:31
    # print('now day:{0}'.format(now_time.day))
    #
    #
    # # 1564557243.8810754 获取到毫秒
    # print(time.time())




    from datetime import datetime,date,time,timedelta
    # 自定义日期和时间
    # d = datetime(2020,10,30,14,5)
    # # 2020-10-30 14:05:00
    # print(d)
    #
    # d2 = date(2019,3,23)
    # # 2019-03-23
    # print(d2)
    #
    # t = time(9,0)
    # # 09:00:00
    # print(t)

    print('---------------------------------')
    # # 日期 时间 字符串之间的相互转换
    # ds = '2018-10-3 13:42:09'
    # ds_t = datetime.strptime(ds, '%Y-%m-%d %H:%M:%S')
    # # 9
    # print(ds_t.second)


    # print('---------------------------------')
    # # datetime对象转换成字符串
    # n = datetime.now()
    # n_str = n.strftime('%Y-%m-%d %H:%M:%S')
    # # 2019-07-31 15:32:21
    # print(n_str)


    # print('---------------------------------')
    # # datetime对象 加减操作
    # n = datetime.now()
    # # 2019-07-31 15:37:15.269619
    # print(n)
    # n_next = n + timedelta(days = 5, hours = 42)
    # # 2019-08-07 09:37:15.269619
    # print(n_next)

    # 时间的减法
    d1 = datetime(2018,10,15)
    d2 = datetime(2018,11,12)

    rest = d2 - d1
    print(dir(rest))

    # 28 相差天数
    print(rest.days)
  • 相关阅读:
    什么是linux的ftp
    linux安装ftp组件
    菜鸟之linux问题之图形界面和dos界面的登录问题
    linux第一面
    vmware下linux系统的安装过程
    vmware的安装
    装饰器的邪门歪道
    关于任务脚本里面用异步
    写类装饰器的2个小问题
    VUE 与其他常见前端框架对比
  • 原文地址:https://www.cnblogs.com/ericblog1992/p/11276847.html
Copyright © 2011-2022 走看看