博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python time 和 datetime 模块
阅读量:4352 次
发布时间:2019-06-07

本文共 1520 字,大约阅读时间需要 5 分钟。

#_*_coding:utf-8_*_

import time   # print(time.clock()) #返回处理器时间,3.3开始已废弃 , 改成了time.process_time()测量处理器运算时间,不包括sleep时间,不稳定,mac上测不出来# print(time.altzone)  #返回与utc时间的时间差,以秒计算\# print(time.asctime()) #返回时间格式"Fri Aug 19 11:14:16 2016",# print(time.localtime()) #返回本地时间 的struct time对象格式# print(time.gmtime(time.time()-800000)) #返回utc时间的struc时间对象格式 # print(time.asctime(time.localtime())) #返回时间格式"Fri Aug 19 11:14:16 2016",#print(time.ctime()) #返回Fri Aug 19 12:38:29 2016 格式, 同上  # 日期字符串 转成  时间戳# string_2_struct = time.strptime("2016/05/22","%Y/%m/%d") #将 日期字符串 转成 struct时间对象格式# print(string_2_struct)# struct_2_stamp = time.mktime(string_2_struct) #将struct时间对象转成时间戳# print(struct_2_stamp)   #将时间戳转为字符串格式# print(time.gmtime(time.time()-86640)) #将utc时间戳转换成struct_time格式# print(time.strftime("%Y-%m-%d %H:%M:%S",time.gmtime()) ) #将utc struct_time格式转成指定的字符串格式  #时间加减import datetime # print(datetime.datetime.now()) #返回 2016-08-19 12:47:03.941925#print(datetime.date.fromtimestamp(time.time()) )  # 时间戳直接转成日期格式 2016-08-19# print(datetime.datetime.now() )# print(datetime.datetime.now() + datetime.timedelta(3)) #当前时间+3天# print(datetime.datetime.now() + datetime.timedelta(-3)) #当前时间-3天# print(datetime.datetime.now() + datetime.timedelta(hours=3)) #当前时间+3小时# print(datetime.datetime.now() + datetime.timedelta(minutes=30)) #当前时间+30分# c_time  = datetime.datetime.now()# print(c_time.replace(minute=3,hour=2)) #时间替换

如需查询详细用法:

  请查看python的帮助文档:  help(time)、help(time.localtime)

 

转载于:https://www.cnblogs.com/song-weiwei/p/10875123.html

你可能感兴趣的文章
Linux下常用的shell命令记录
查看>>
HTTP 常用 Header 讲解
查看>>
linux分割字符串操作
查看>>
PHP学习2
查看>>
多实例Mysql配置
查看>>
KOA中间件源码解析
查看>>
Mapnik使用postgres中的栅格数据
查看>>
Java学习之异常处理
查看>>
combox的DispalyMember和ValueMember属性的测试
查看>>
Start Developing Mac Apps -- Human Interface Design 用户界面设计
查看>>
linux下安装Mongodb
查看>>
Page.RegisterStartupScript和Response.Write的区别。
查看>>
hdu4348区间更新的主席树+标记永久化
查看>>
bzoj3261: 最大异或和 可持久化trie
查看>>
ZOJ 2532 Internship
查看>>
HDU 3452 Bonsai
查看>>
[Erlang12] Mnesia分布式应用
查看>>
图的遍历 | 1013 连通块块数
查看>>
Kinect 开发 —— 进阶指引(上)
查看>>
python学习笔记(六)time、datetime、hashlib模块
查看>>