time模块清楚三种格式的时间相互转换

import time
# 时间分为三种格式
#1、时间戳
start= time.time()
time.sleep(3)
stop= time.time()
print(stop - start) #2、格式化的字符串形式
print(time.strftime('%Y-%m-%d %X'))
print(time.strftime('%Y-%m-%d %H:%M:%S %p')) #3、 结构化的时间/时间对象
t1=time.localtime()
print(t1)
print(type(t1.tm_min))
print(t1.tm_mday) #通过对象里的属性可以直接进行取值 t2=time.gmtime() # 和localtime一样,都是时间对象,可以通过变量直接取值
print(t1)
print(t2)

2.时间转换

时间转换
print(time.localtime(123123123)) # 转换为格式化对象
print(time.gmtime(123123123)) print(time.mktime(time.localtime())) #格式化对象转化为时间戳 print(time.strftime('%Y',time.localtime()))
print(time.strptime('2011-03-07','%Y-%d-%m'))
print(time.asctime())
print(time.ctime())
print(time.strftime('%a %b %d %H:%M:%S %Y')) print(time.asctime(time.localtime()))
print(time.ctime(123123123)) print(time.strftime('%Y-%m-%d %X')) datetime 模块
# 获取格式化字符串形式的时间麻烦
# 时间戳与格式化时间之间的转换麻烦
# 获取之前或者未来的时间麻烦
import datetime print(datetime.datetime.now())
print(datetime.datetime.fromtimestamp(1231233213)) print(datetime.datetime.now() + datetime.timedelta(days=3))
print(datetime.datetime.now() + datetime.timedelta(days=-3)) s=datetime.datetime.now()
print(s.replace(year=2020))
												

最新文章

  1. 【工匠大道】markdown使用技巧
  2. Postgre cannot insert multiple commands into a prepared statement
  3. ThroughRain第二次冲刺总结
  4. 经典SQL语句大全_主外键_约束
  5. js bom中浏览器兼容问题判断代码
  6. Entity Framework Code First ---EF Power Tool 和MySql一起使用遇到的问题
  7. Android事件机制
  8. IDEA上传项目至git
  9. postgresql搭建从库
  10. 解决Configuration 'compile' is obsolete and has been replaced with implementation
  11. SQLServer数据库文件由高版本向低版本转换
  12. 从零基础到拿到网易Java实习offer,谈谈我的学习经验
  13. 【转】AJAX中JSON数据的返回处理问题
  14. Tests for Variances
  15. react-router v4.0 知识点
  16. [视频]K8飞刀 ms15022 office漏洞演示动画
  17. 【转】Mapped Statements collection does not contain value for解决
  18. Spring和Mybatis整合过程中遇到的一个找不到sqlSessionFactory或sqlSessionTemplate的异常
  19. myeclipse 10 +Axis2 1.62 开发WebService手记
  20. 《Android源码设计模式》--策略模式

热门文章

  1. 有关java构造器的笔记
  2. android抓log
  3. 两个喜欢的"新"C#语法
  4. IT江湖--这个冬天注定横尸遍野(多数人技术迟迟无进阶,多半是懒的原因。勤是必须的)
  5. mac下破解apk文件以及apktool的相关使用
  6. Lightoj 1017 - Brush (III)
  7. 在 linux 下使用 CMake 构建应用程序【转】
  8. 一步一步学Silverlight 2系列(3):界面布局
  9. Evernote相关技术介绍——mysql+lucene+tomcat
  10. Android JNI MAC OS环境配置