zoukankan      html  css  js  c++  java
  • datatime模块

    import datetime
    import time
    
    astime = '2019-07-17 08:21:05'
    # 求 astime 5h后的时间
    # 1.转成时间戳  2.datetime.datetime.fromtimestamp(int(时间戳)) + datetime.timedelta(hours=10)  int时间戳因为不需要毫秒
    
    astime_timestamp = time.mktime(time.strptime(astime,'%Y-%m-%d %H:%M:%S'))  # 转成时间戳
    print(astime_timestamp) #1563322865.0
    res = datetime.datetime.fromtimestamp(int(astime_timestamp)) + datetime.timedelta(hours=10) #当前时间+10小时
    print(res) #2019-07-17 18:21:05
    print(type(res)) #<class 'datetime.datetime'>
    #要想变成对应字符串要str强转一下


    判断是不是周几:

    astime_timestamp = time.mktime(time.strptime('2019-08-04 08:21:05','%Y-%m-%d %H:%M:%S'))  # 转成时间戳
    
    res = datetime.datetime.fromtimestamp(int(astime_timestamp)) + datetime.timedelta(hours=10) #当前时间+10小时
    print(res) #2019-07-17 18:21:05
    
    print(res.weekday()+1) #7 周日    datetime对象.weekday() 返回周几

  • 相关阅读:
    React Children 使用
    Redux 中间件和异步操作
    Redux 核心概念
    React 的setState 异步理解
    JS 中类型和类型转换
    ES6 新增集合----- Set 和Map
    ES6 新增基本数据类型Symbol
    ES6 解构赋值
    ES6 对象增强
    ES6 中的let 和 const
  • 原文地址:https://www.cnblogs.com/dingyunfeng/p/11300789.html
Copyright © 2011-2022 走看看