Python:time模块、calendar模块
time模块
import time
获取时间戳
>>>time.time()
#1532418950.7246091
获取时间元组
>>> time.localtime() #time.struct_time(tm_year=2018, tm_mon=7, tm_mday=24, tm_hour=15, tm_min=56, tm_sec=42, tm_wday=1, tm_yday=205, tm_isdst=0)
'''
|tm_year| 4位数年 | 2018|
|tm_mon| 月| 1 到 12|
|tm_mday| 日| 1 到 31|
|tm_hour | 小时| 0 到 23|
|tm_min | 分钟|0 到 59|
|tm_sec | 秒|0 到 61 (61 是闰秒)|
|tm_wday| 一周的第几日| 0到6 (0是周一)|
|tm_yday | 一年的第几日|1 到 366(儒略历)|
|tm_isdst | 是否为夏令时|-1, 0, 1|
'''
生成固定格式的时间表示格式
'''
直接asctime
把一个表示时间的元组或者struct_time*表示为'Tue Jul 24 16:25:39 2018'这种形式。如果没有给参数,会将time.localtime()作为参数传入
''' >>> time.asctime() #'Tue Jul 24 16:25:39 2018' '''
把一个时间戳(按秒计算的浮点数)转化为time.asctime()的形式
''' >>> time.ctime() #'Tue Jul 24 16:25:39 2018'
时间格式化
>>> time.strftime('%Y-%m-%d %H:%M:%S')
#'2018-07-24 15:58:00'
#注意大小写别写错,下面是图方便遇到的坑
>>> time.strftime('%y-%m-%d %h:%m:%s')
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
time.strftime('%y-%m-%d %h:%m:%s')
ValueError: Invalid format string
calendar(日历)模块
import calendar from calendar import * #给下面调用偷个懒
显示年日历
k = calendar(2018)
print(k)
打印某月日历
m = calendar.month(2017, 7)
print(m)
Python:time模块、calendar模块的更多相关文章
- python标准库-calendar 模块
原文地址:http://www.bugingcode.com/blog/python_calendar.html calendar 模块是python实现的unix 的 cal命令.它可以以标准的模式 ...
- time模块/datetime模块/calendar模块
time模块时间的表示形式时间戳:以整型或浮点型表示⼀个时间,该时间以秒为单位,这个时间是以1970年1⽉1⽇0时0分0秒开始计算的. 导入time import time 1.返回当前的时间戳 no ...
- datetime模块+calendar模块
datetime: """ 模块中的类: datatime 同时有时间和日期 timedelta 主要用于计算时间的跨度 tzinfo 时区相关 time 只关注时间 d ...
- python之模块calendar(汇集了日历相关的操作)
# -*- coding: utf-8 -*- #python 27 #xiaodeng #calendar日历模块 import calendar #3个大类: calendar.Calendar( ...
- 小白学 Python(22):time 和 calendar 模块简单使用
人生苦短,我选Python 前文传送门 小白学 Python(1):开篇 小白学 Python(2):基础数据类型(上) 小白学 Python(3):基础数据类型(下) 小白学 Python(4):变 ...
- python Calendar 模块导入及用法
Calendar 是python 日历模块,此模块的函数都是日历相关的,例如打印某月的字符月历,星期之类的模块,下面剖析python Calendar 模块导入及用法. 1,python导入日历模块 ...
- python日期与日历Datetime和Calendar模块
datetime模块 1.1 概述 datetime比time高级了不少,可以理解为datetime基于time进行了封装,提供了更多的实用的函数,datetime的接口更加的直观,更容易调用 1.2 ...
- python五十五课——calendar模块
4.calendar模块: 构造:calendar(year,[w=2,l=1,c=6]):返回year年的完整的日历信息对象 和闰年相关的函数如下: isleap(year):判断year是否是闰年 ...
- Python基础—10-常用模块:time,calendar,datetime
#常用模块 time sleep:休眠指定的秒数(可以是小数) time:获取时间戳(从1970-01-01 00:00:00到此刻的秒数) localtime:将一个时间戳转换为一个对象,对象中包含 ...
- Python常用模块-时间模块
在写代码的过程中,我们常常需要与时间打交道,在python中,与时间处理有关的模块有time,datetime和calendar.,这里主要介绍time和datetime模块 在python中,表示时 ...
随机推荐
- Winform开发框架之通用Windows摄像头调用拍照--SNF快速开发平台3.3-Spring.Net.Framework
今天做了一个windows系统下调用摄像头.进行开启.关闭.拍照.设置等等功能演示. 进行源码贡献,欢迎大家下载使用 一.DEMO效果如下: 二.DEMO演示代码如下: using SNF.Utili ...
- 全面理解Javascript闭包和闭包的几种写法及用途【转】
一.什么是闭包和闭包的几种写法和用法 1.什么是闭包 闭包,官方对闭包的解释是:一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分.闭包的特点: 1. ...
- 物联网架构成长之路(13)-SpringBoot入门
1. 前言 下载最新版的JavaEE eclipse-jee-oxygen-2-win32-x86_64.zip 安装STS插件 Window->Eclipse Marketplace -> ...
- Haproxy全透明代理
1. 系统环境搭建 操作系统Centos7 内核版本3.10 Centos7已自带TPROXY模块,不需要安装TPROXY 2. Haproxy下载,编译,安装,配置 下载地址 http://www. ...
- Current online Redo 和 Undo 损坏的处理方法
转自:http://blog.csdn.net/tianlesoftware/article/details/6261475 Oracle 不同故障的恢复方案 http://blog.csdn.net ...
- Andorid开发(二十二)——获取上下文getApplicationContext()、Activity.this、 getBaseContext
getApplicationContext() //返回应用的上下文,生命周期是整个应用,应用摧毁它才摧毁 Activity.this的context //返回当前activity的上下文,属于act ...
- 【iCore1S 双核心板_ARM】例程十一:RTC实时时钟实验——显示时间和日期
实验现象: 核心代码: int main(void) { /* USER CODE BEGIN 1 */ RTC_DateTypeDef sDate; RTC_TimeTypeDef sTime; u ...
- 阿里云中ssl配置(nginx安装https服务)
1.配置 a.阿里云服务器 b.安装了nginx,php等 2.申请免费ssl证数 a. b. c.产看ssl证数 d.下载证数 e,这里我下载的是nginx(crt与key文件) f.服务器上配置 ...
- SpringBatch的流程简介
SpringBatch的流程图如下: 每个Batch都会包含一个Job.Job就像一个容器,这个容器装了若干Step,Batch中实际干活的也就是这些Step,至于Step干什么活,无外乎读取数据,处 ...
- [Bayes] runif: Inversion Sampling
runifum Inversion Sampling 看样子就是个路人甲. Ref: [Bayes] Hist & line: Reject Sampling and Importance S ...