一、明确时间元组

二、测试代码
#!/usr/bin/env python
# -- coding: utf-8 --'
"""
时间模块,time的相关操作与测试
"""
# python中time模块使用例子
import time # 1493368879.41,时间戳
print time.time() # 获取的是一个元组,time.struct_time(tm_year=2017, tm_mon=4, tm_mday=28,
# tm_hour=16, tm_min=41, tm_sec=19, tm_wday=4, tm_yday=118, tm_isdst=0)
print time.localtime()
print time.localtime(time.time()) #格式化时间
# Fri Apr 28 16:31:38 2017
print time.asctime(time.localtime(time.time())) # 时间格式转换,参数(格式,元组)
print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print time.strftime("%y/%m/%d %H/%M/%S", time.localtime())
print time.strftime("%Y--%m--%d %H--%M--%S", time.localtime())
print time.strftime("%Y %m %d %H--%M--%S", time.localtime()) # 格式化成Sat Mar 28 22:24:24 2016形式
print time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()) # 字符串转换成元组
strtime ="2017/08/23" #元组类型
print time.strptime(strtime,"%Y/%m/%d") # 元组转换成时间戳
print time.mktime(time.strptime(strtime,"%Y/%m/%d"))
#----------------------------------------------------------------------------------------------
三、python中时间日期格式化符号:
  • %y 两位数的年份表示(00-99)
  • %Y 四位数的年份表示(000-9999)
  • %m 月份(01-12)
  • %d 月内中的一天(0-31)
  • %H 24小时制小时数(0-23)
  • %I 12小时制小时数(01-12)
  • %M 分钟数(00=59)
  • %S 秒(00-59)
  • %a 本地简化星期名称
  • %A 本地完整星期名称
  • %b 本地简化的月份名称
  • %B 本地完整的月份名称
  • %c 本地相应的日期表示和时间表示
  • %j 年内的一天(001-366)
  • %p 本地A.M.或P.M.的等价符
  • %U 一年中的星期数(00-53)星期天为星期的开始
  • %w 星期(0-6),星期天为星期的开始
  • %W 一年中的星期数(00-53)星期一为星期的开始
  • %x 本地相应的日期表示
  • %X 本地相应的时间表示
  • %Z 当前时区的名称
  • %% %号本

四、测试代码结果

  

Python时间time模块介绍的更多相关文章

  1. python 时间time模块介绍和应用

    1.其中format_string 类型的时间和struct_time之间可以转换,timestamp时间戳可以和struct_time之间进行转化,但是时间戳和格式化时间是不能直接转换的. time ...

  2. Python时间calender模块介绍

    获取某月日历 Calendar模块有很广泛的方法用来处理年历和月历,例如打印某月的月历: #!/usr/bin/python # -*- coding: UTF-8 -*- import calend ...

  3. python时间Time模块

    时间和日期模块 关注公众号"轻松学编程"了解更多. python程序能用很多方式处理日期和时间,转换日期格式是一种常见的功能. python提供了一个time和calendar模块 ...

  4. Python中的模块介绍和使用

    在Python中有一个概念叫做模块(module),这个和C语言中的头文件以及Java中的包很类似,比如在Python中要调用sqrt函数,必须用import关键字引入math这个模块,下面就来了解一 ...

  5. Python 正则表达式——re模块介绍

    Python 正则表达式 re 模块使 Python 语言拥有全部的正则表达式功能,re模块常用方法: re.match函数 re.match从字符串的起始位置匹配,如果起始位置匹配不成功,则matc ...

  6. python时间-time模块

    time是python自带的模块,用于处理时间问题,提供了一系列的操作时间的函数. 以下说明针对于 python2.7,其他版本可能有所差异. 模块提供了两个种表示时间的格式: 1.时间戳,是以秒表示 ...

  7. python 爬虫 urllib模块介绍

    一.urllib库 概念:urllib是Python自带的一个用于爬虫的库,其主要作用就是可以通过代码模拟浏览器发送请求.其常被用到的子模块在Python3中的为urllib.request和urll ...

  8. python:时间处理模块

    # coding=utf-8 from datetime import date, datetime import time def date_test(): print 'date.max', da ...

  9. python 中 urlparse 模块介绍

    urlparse模块主要是用于解析url中的参数  对url按照一定格式进行 拆分或拼接 1.urlparse.urlparse 将url分为6个部分,返回一个包含6个字符串项目的元组:协议.位置.路 ...

随机推荐

  1. Exception (3) Java exception handling best practices

    List Never swallow the exception in catch block Declare the specific checked exceptions that your me ...

  2. Digital image processing(数字图像处理)

    In computer science, digital image processing is the use of computer algorithms to perform image pro ...

  3. 关于搜索elasticsearch的数据条数大于10000的坑 max_result_window的两种设置方式

    当用elasticsearch进行深度分页查询时的size-from大于10000的时候,就会报错“”, 官方推荐是scroll查询返回结果是无序的不满足业务需求,所以还是通过设置最大返回结果数来达到 ...

  4. Django进阶(转载)

    Django进阶地址 来自为知笔记(Wiz)

  5. Reporting Service服务SharePoint集成模式安装配置(6、安装Reporting services Add-in for SharePoint 外接程序)

    第五步骤 : 安装Reporting services Add-in for SharePoint 外接程序 RS 外接程序是在 SharePoint 服务器上运行用于 SharePoint 产品的 ...

  6. SQLite Mysql 模糊查找(like)

    select UserId,UserName,Name,Sex,Birthday,Height,Weight,Role from xqhit_Users where UserName like &qu ...

  7. eclipse问题 - windows版

    问题:java compiler level does not match the version of the installed java project facet:但是项目仍能运行 解释:项目 ...

  8. cmd应用

    如何用cmd命令新建和打开一个隐藏文件夹 随着电脑的广泛应用,个人电脑的私人空间越来越大,很多人喜欢把个人的一些私隐的文件存放在电脑上,私隐文件当然是不想别人看到的,为了防止别人看不见自己的文件,可以 ...

  9. 51nod-迷宫问题(Dijkstra算法)

    关于Dijkstra算法的博文 http://www.cnblogs.com/skywang12345/p/3711512.html#anchor2 Dijkstra算法是一个经典的算法——他是荷兰计 ...

  10. swoft| 源码解读系列一: 好难! swoft demo 都跑不起来怎么破? docker 了解一下呗~

    title: swoft| 源码解读系列一: 好难! swoft demo 都跑不起来怎么破? docker 了解一下呗~description: 阅读 sowft 框架源码, swoft 第一步, ...