zoukankan      html  css  js  c++  java
  • datetime模块+calendar模块

    datetime:

    """
    模块中的类:
    datatime    同时有时间和日期
    timedelta   主要用于计算时间的跨度
    tzinfo      时区相关
    time        只关注时间
    date        只关注日期
    
    """
    import datetime
    
    #获取当前时间
    d1 = datetime.datetime.now()
    print(d1)
    print(type(d1))
    
    #获取指定的时间
    d2 = datetime.datetime(1999,10,1,10,28,25,564825)
    print(d2)
    
    #将时间转为字符串
    d3 = d1.strftime("%y-%m-%d %X")
    print(d3)
    print(type(d3))
    
    #将格式化字符串转为datetime对象
    #转换的格式要与字符串一致
    d4 = datetime.datetime.strptime(d3,"%y-%m-%d %X")
    print(d4)
    print(type(d4))
    
    d5 =datetime.datetime(1999,10,1,10,28,25,123456)
    d6 = datetime.datetime.now()
    d7 = d6-d5
    print(d7)
    print(type(d7))
    #间隔的天数
    print(d7.days)
    #间隔天数除外的秒数
    print(d7.seconds)

    calendar:

    import calendar
    
    """
    日历模块
    """
    
    #使用
    
    #返回指定某年某月的日历
    print(calendar.month(2018,11))
    
    #返回指定年的日历
    # print(calendar.calendar(2018))
    
    #闰年返回True, 否则返回False
    # print(calendar.isleap(2018))
    
    #返回某个月的weekday的第一天和这个月所有的天数
    # print(calendar.monthrange(2018,11))
    
    #返回某个月以每一周为元素的列表
    print(calendar.monthcalendar(2018,7))
  • 相关阅读:
    IOS-UI基础-图片浏览器
    IOS-UI基础-UIImageView帧动画
    IOS-UI-transform
    IOS-UI基础-按钮扩展
    IOS-UI基础-UIView和UIViewController
    IOS-UI基础-按钮
    OC-关于COPY关键字
    OC-NSNumber与NSValue
    OC-NSFileManager创建目录
    2019规划目标
  • 原文地址:https://www.cnblogs.com/allwell/p/9986054.html
Copyright © 2011-2022 走看看