time模块,datetime模块
time模块
time模块是包含各方面对时间操作的函数. 尽管这些常常有效但不是所有方法在任意平台中有效。
时间相关的操作,时间有三种表示方式:
- 时间戳 1970年1月1日之后的秒,即:time.time()
- 格式化的字符串 2014-11-11 11:11, 即:time.strftime('%Y-%m-%d')
- 结构化时间 元组包含了:年、日、星期等... time.struct_time 即:time.localtime()
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
import time# ========== 时间戳 ==========print time.time() print time.mktime(time.localtime()) # ========== 元组形式 ==========print time.gmtime() #可加时间戳参数print time.localtime() #可加时间戳参数print time.strptime('2014-11-11', '%Y-%m-%d') # ========== 字符串形式 ==========print time.strftime('%Y-%m-%d') #默认当前时间print time.strftime('%Y-%m-%d',time.localtime()) #默认当前时间print time.asctime()print time.asctime(time.localtime())print time.ctime(time.time())"""格式化占位符: %Y Year with century as a decimal number. %m Month as a decimal number [01,12]. %d Day of the month as a decimal number [01,31]. %H Hour (24-hour clock) as a decimal number [00,23]. %M Minute as a decimal number [00,59]. %S Second as a decimal number [00,61]. %z Time zone offset from UTC. %a Locale's abbreviated weekday name. %A Locale's full weekday name. %b Locale's abbreviated month name. %B Locale's full month name. %c Locale's appropriate date and time representation. %I Hour (12-hour clock) as a decimal number [01,12]. %p Locale's equivalent of either AM or PM.""" |

datetime模块
datetime模块提供对于日期和时间进行简单或复杂的操作. datetime 模块提供了一下的可用类型(Available Types)。
- datetime.MINYEAR 和 datetime.MAXYEAR 模块常量表示datetime接受的范围
- class datetime.date: 一个理想化的日期, 提供year, month, day属性
- class datetime.time: 一个理想化的时间, 提供hour, minute, second, microsecond, tzinfo.
- class datetime.datetime: 日期和时间的组合.提供year, month, day, hour, minute, second, microsecond, tzinfo.
- class datetime.timedelta: 表达两个date,time和datetime持续时间内的微妙差异.
- class datetime.tzinfo: 时间对象的抽象基类.
|
1
2
3
4
|
# 时间相减import datetimeprint datetime.datetime.now()print datetime.datetime.now() - datetime.timedelta(days=5) |
time模块,datetime模块的更多相关文章
- Python模块01/自定义模块/time模块/datetime模块/random模块
Python模块01/自定义模块/time模块/datetime模块/random模块 内容大纲 1.自定义模块 2.time模块 3.datetime模块 4.random模块 1.自定义模块 1. ...
- Python全栈之路----常用模块----datetime模块详解
相比于time模块,datetime模块的接口则更直观,更容易调用. datetime模块定义了下面这几个类: datetime.date:表示日期的类,常用的属性有year,month,day: d ...
- python模块-datetime模块
上面一篇已经讲了time模块,再来学习datetime模块. datetime主要有datetime.timedelta.time.date这4个子模块. a.datetime常用的函数(dateti ...
- 常用模块 - datetime模块
一.简介 datetime是Python处理日期和时间的标准库. 1.datetime模块中常用的类: 类名 功能说明 date 日期对象,常用的属性有year, month, day time 时间 ...
- 模块-os.system的两个模块/random模块/datetime模块/写日志
一.获取当前目录的路径 os.path.abspath('.')# 取绝对路径 os.getcwd()# 取当前路径 .代表当前目录 ..上一级目录 ../.. 二.执行操作系统命令1.os.syst ...
- Python3 time模块&datetime模块&random模块
''' time模块 ''' # import time # print(help(time)) # help()提供帮助 # print(time.time()) # 1970年开始到现在的秒数(时 ...
- time模块/datetime模块/calendar模块
time模块时间的表示形式时间戳:以整型或浮点型表示⼀个时间,该时间以秒为单位,这个时间是以1970年1⽉1⽇0时0分0秒开始计算的. 导入time import time 1.返回当前的时间戳 no ...
- time模块 datetime 模块 random 模块 OS 模块 sys 模块 hashlib 模块
time模块 在python中的时间表现形式: 时间戳 (自1970-01-01-00-00 到当前时间,按秒计算,一共过了多少秒 格式化时间 返回的是时间的字符串 格式化时间对象 返回的是一个元组 ...
- python模块 | 时间处理模块—datetime模块
在python中,与时间处理相关的模块有 time,datetime,calendar. 时间的两个概念: UTC(世界协调时): 整个地球分为二十四时区,每个时区都有自己的本地时间.格林威治天文时间 ...
- time模块&datetime模块
import time a=time.localtime(time.time()) #将时间戳转换为当前时区的元组 print(a) c=time.gmtime(time.time()) #把时间戳转 ...
随机推荐
- 【scrapy】创建第一个项目
1)创建项目命令: scrapy startproject tutorial 该命令将在当前目录下创建tutorial文件夹 2)定义Item Items are containers that wi ...
- css中高度比img多出4px的问题
一句话概括:为什么<a>标签比里面的img高度多出4px 的问题,主要还是由于 img是inline element, it's height is caculated different ...
- POJ2573 Bridge 经典的过桥问题
曾经遇到过类似的.纪念一下!这题同一时候也是 ZOJ1877.经典的过桥问题 是有个博客解说的非常好的 戳这里 挺久曾经.遇到过一个基本一样的,那个题目仅仅要求求出 最短时间就可以,如今还有过桥的过 ...
- SpringMVC+Hibernate+Junit4+json基本框架近乎0配置
公司是做APP开发的,须要后台来提供接口,于是乎,这个任务就交给我,经过重复的尝试,学习和參考别人的demo,最终搭出自己还算惬意的框架.SpringMVC+Sping3+Hibernate4+Jun ...
- 【转载】TCP和TCP/IP的区别
TCP/IP协议(Transmission Control Protocol/Internet Protocol)叫做传输控制/网际协议, 又叫网络通讯协议,这个协议是Internet国际互联网络的基 ...
- 怎样用Google APIs和Google的应用系统进行集成(8)----怎样把Google Blogger(博客)的JSON Schema转换成XML的Schema(XSD)?
在Google RESTFul API中,Google Blogger API(Google博客API)应该和我们的生活离得近期:由于差点儿非常多人每天都在看博客,都在写博客,都听说过博客.在前面的G ...
- superCleanMaster
https://github.com/eltld/superCleanMaster
- FancyCoverFlow
https://github.com/davidschreiber/FancyCoverFlow
- Spring中AOP的使用
问题:什么是AOP? 答:AOP基本概念:Aspect-Oriented Programming,面向方面编程的简称,Aspect是一种新的模块化机制.用来描写叙述分散在对象.类或方法中的横切关注点( ...
- 大话设计模式C++实现-第14章-观察者模式
一.UML图 关键词:Subject维护一个Observer列表.Subject运行Notify()时就运行列表中的每一个Observer的Update(). 二.概念 观察者模式:定义了一种一对多的 ...