由于要用到时间模块,为了下次不用去翻文档,这里也简单记录一下:

直接一个脚本看输出:

import time
print time.time()
print time.localtime(time.time())
print time.strftime('%Y-%m-%d', time.localtime())
print time.strftime('%y-%m-%d', time.localtime())
print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
print time.strftime('%Y-%m-%d %I:%M:%S', time.localtime())
print time.strftime('%Y-%m-%d %H:%M:%S --%A--%c', time.localtime())
print time.strftime('%Y-%m-%d %H:%M:%S --%x--%X', time.localtime())

查看结果:

[root@www python]# python time1.py
1425623399.84
time.struct_time(tm_year=2015, tm_mon=3, tm_mday=6, tm_hour=14, tm_min=29, tm_sec=59, tm_wday=4, tm_yday=65, tm_isdst=0)
2015-03-06
15-03-06
2015-03-06 14:29:59
2015-03-06 02:29:59
2015-03-06 14:29:59 --Friday--Fri Mar  6 14:29:59 2015
2015-03-06 14:29:59 --03/06/15--14:29:59datetime模块定义了下面这几个类:
datetime.date:表示日期的类。常用的属性有year, month, day;
datetime.time:表示时间的类。常用的属性有hour, minute, second, microsecond;
datetime.datetime:表示日期时间。
datetime.timedelta:表示时间间隔,即两个时间点之间的长度。>>> from datetime import *
>>> print datetime.today()
2015-03-06 14:43:46.870936
>>> print datetime.now()
2015-03-06 14:43:51.313098

需求:查看100天前是几月几号:

import datetime
(datetime.datetime.now() - datetime.timedelta(days = 100)).strftime("%Y-%m-%d")

python 时间模块备忘相关推荐

  1. python时间模块time详解

    python时间模块time详解 在平常的代码中,我们常常需要与时间打交道.在Python中,与时间处理有关的模块就包括:time,datetime以及calendar.这篇文章,主要讲解time模块 ...

  2. 【Python基础】Python时间模块,超实用总结!

    我的施工之路 施工之路已完成13篇图文,又提炼为思维导图,结合使用,效果最佳. 1我的施工计划 2数字专题 3字符串专题 4列表专题 5流程控制专题 6编程风格专题 7函数使用 8面向对象编程(上篇) ...

  3. c++获取当前时间戳_python开发:python时间模块的使用

    前言: 今天元宵节,祝福大家元宵节快乐. 今天在元宵节给各位朋友分享一下python时间模块. 我们在开发中经常会与时间打交道,如:获取事件戳,时间戳的格式化等,这里简要记录一下python操作时间的 ...

  4. python时间模块倒计时_Python时间模块

    python时间模块倒计时 In this tutorial, we will learn about the Python time module. Python Variable is discu ...

  5. python安装库备忘

    python安装库备忘 参考 pip注意事项 python库备忘 参考 Python开发之pip使用详解 pypi pypi pip注意事项 默认安装库时按最新版本安装,可能把以前的库冲掉,造成版本不 ...

  6. python时间模块哪个好arrow模块_python库: arrow (时间)

    arrow是个时间日期库,简洁易用.支持python3.6 https://arrow.readthedocs.io/en/latest/ arrow官网api https://github.com/ ...

  7. python 时间模块 time datetime calendar

    学而时习之,不亦悦乎.经常的复习下之前的知识,不仅加深.巩固记忆,还能在复习的同时,查漏补缺.  今天针对python库自带的三个时间模块进行复习.... time模块 time模块提供各种操作时间的 ...

  8. python时间模块 datetime (datetime、timedelta和timezone部分)

    本文承接前文:https://blog.csdn.net/weixin_44013214/article/details/103116581 本文介绍时间模块datetime的剩余部分的内容 date ...

  9. python时间模块设置_Python之时间和日期模块

    1.import time 先要导入时间模块 1)time.time()得到当前的时间,返回的是时间戳,表示自1970年1月1日起到程序运行时的秒数 1 importtime2 print(time. ...

最新文章

  1. 【错误记录】Android Studio 编译报错 ( AppCompat does not support the current theme features )
  2. ASP.NET Core的配置(2):配置模型详解
  3. Facebook泄露隐私算什么?国内一次外卖,竟让4万用户全“裸着”
  4. JAVA从文件中取出特定的_从Java中的文本文件读取特定的行
  5. WebLogic简单的备份和恢复
  6. 苹果mac智能手写笔记软件:GoodNotes 5 +iCloud同步
  7. Android游戏开发–基本游戏架构
  8. 开源公告|腾讯 PAG 动画组件对外开源
  9. 美赛论文成绩批量爬取
  10. 个人免签约支付程序,支付宝免签约,码支付,微信免签约支付源码,paypai
  11. 计算机音乐因为我刚好遇见你,因为我刚好遇见你歌曲
  12. 金蝶K3 SQL报表系列-委外未勾稽明细表
  13. c语言中输出姓名身高,c语言输出身高:男生身高=(爸身高+妈身高)×0.54 女生身高=(爸身高×0.92+妈身高)÷2...
  14. php socket recv 超时,socket编程中的超时设置示例详解之一
  15. C#毕业设计——基于C#+asp.net+sqlserver的学生成绩管理系统设计与实现(毕业论文+程序源码)——成绩管理系统
  16. 搜狗大数据总监、Polarr 联合创始人关于深度学习的分享交流
  17. 2022年苏州大学872真题整理【回忆版】
  18. 虚拟创业云|BBC幼儿英语启蒙动画Nina and the Neurons妮娜和神经元
  19. 漫画软件开发:EasyComic
  20. 三星手机安装linux系统下载,技术|在手机上轻松安装 Ubuntu Touch OS

热门文章

  1. 大专生如何报考MBA
  2. WAF Bypass数据库特性(Mysql探索篇)
  3. 远程SSH连接服务与基本排错
  4. Linux学习总结(3)——Linux实用工具
  5. windows备份与还原和两个主机的相互通信
  6. ylb:SQL 常用函数
  7. 如何学习iphone游戏开发
  8. [论文笔记] Fast Quality Driven Selection of Composite Web Services (ECOWS, 2006)
  9. 重磅消息:蚂蚁金服推出RPC框架
  10. 如何从机器学习数据中获取更多收益