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()) #把时间戳转 ...
随机推荐
- C/C++实现bmp文件读写
之前知道点bmp图的格式,然后对8位操作过,然后今天弄了一下24位真彩色的. C++读取.旋转和保存bmp图像文件编程实现 主要是理解bmp文件的格式8/24位的区别 8位图有调色板,24位在文件头和 ...
- HDU 4115 Eliminate the Conflict(2-sat)
HDU 4115 Eliminate the Conflict pid=4115">题目链接 题意:Alice和Bob这对狗男女在玩剪刀石头布.已知Bob每轮要出什么,然后Bob给Al ...
- SQL FULL OUTER JOIN 关键字
SQL FULL OUTER JOIN 关键字 SQL FULL OUTER JOIN 关键字 FULL OUTER JOIN 关键字只要左表(table1)和右表(table2)其中一个表中存在匹配 ...
- iOS 沙盒文件操作
//获得document +(NSString *)documentsPath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDoc ...
- ios开发--NSDate与NSDateFormatter的相关用法【转】
原文地址:http://blog.sina.com.cn/s/blog_91ff71c0010188u9.html 1.NSDateFormatter配合NSDate与NSString之间的转化 N ...
- 清理一下电脑垃圾,打开Eclipse发现左边的所有项目消失了
使用360清理一下电脑垃圾,打开Eclipse发现左边的所有项目消失了,但在相应的workspace能够找到项目,这个问题已经是第三次遇到了(预计是被360清理掉Eclipse的一些部署或配置文件所导 ...
- VS创建Web项目提示配置IISExpress失败
开发服务器VS2013,新建Web项目提示: 打开Web项目提示: 解决方法:控制面板,找到IISExpress,右键 选择修复,解决问题..
- Educational Codeforces Round 18 C. Divide by Three DP
C. Divide by Three A positive integer number n is written on a blackboard. It consists of not more ...
- cxf与struts2拦截器冲突的解决方案
最近学习接口,学习了下cxf,用tomcat部署访问的时候,发现接口不能访问:百度了很多,最终找到比较好的解决方案: sturts2配置: <!-- 设置strus拦截器 --> < ...
- 使用buildroot搭建linux文件系统【转】
本文转载自:http://blog.csdn.net/metalseed/article/details/45423061 (文件系统搭建,强烈建议直接用buildroot,官网上有使用教程非常详细b ...