python3.7 time模块
#!/usr/bin/env python
__author__ = "lrtao2010" #python3.7 time模块 #time模块没有time.py文件,是内置到解释器中的模块 #三种时间表示方式
'''
1、时间戳(timestamp): 通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量。
2、格式化的时间字符串:"2018-09-03 10:02:01"
3、元组(struct_time):struct_time元组共有9个元素共九个元素:(年,月,日,时,分,秒,一年中第几周,一年中第几天,夏令时)
''' import time #时间戳 time()
# print(time.time())
# 1535939025.4159343 #struct_time
#localtime([secs]) 将一个时间戳转换为当前时区的struct_time。secs参数未提供,则以当前时间为准。
#当地时间
# print(time.localtime(time.time()))
# time.struct_time(tm_year=2018, tm_mon=9, tm_mday=3, tm_hour=9, tm_min=46, tm_sec=7, tm_wday=0, tm_yday=246, tm_isdst=0)
# print(time.localtime()) #
# time.struct_time(tm_year=2018, tm_mon=9, tm_mday=3, tm_hour=9, tm_min=48, tm_sec=19, tm_wday=0, tm_yday=246, tm_isdst=0) # t_local=time.localtime()
# print(t_local.tm_year)
# print(t_local.tm_mon)
# print(t_local.tm_mday)
#
#
# #gmtime([secs]) 将一个时间戳转换为UTC时区(0时区)的struct_time。
# print(time.gmtime())
# time.struct_time(tm_year=2018, tm_mon=9, tm_mday=3, tm_hour=1, tm_min=51, tm_sec=38, tm_wday=0, tm_yday=246, tm_isdst=0) #mktime(t) : 将一个struct_time转化为时间戳。
# print(time.mktime(time.localtime()))
# 1535939934.0 # asctime([t]) : 把一个表示时间struct_time表示为这种形式:'Mon Sep 3 10:01:46 2018'。
# 默认将time.localtime()作为参数传入。 # print(time.asctime())
# Mon Sep 3 10:01:46 2018 #ctime([secs]) : 把一个时间戳转化为time.asctime()的形式,默认time.time()为参数。
# print(time.ctime())
# Mon Sep 3 10:05:40 2018 #strftime(format[, t])
# 把一个代表时间的struct_time转化为格式化的时间字符串。
# 如果t未指定,将传入time.localtime()。
# 如果元组中任何一个元素越界,ValueError的错误将会被抛出。
# print(time.strftime("%Y-%m-%d %X")) #%X 等同于 %H%M%S
# print(time.strftime("%Y-%m-%d %X",time.localtime()))
# print(time.strftime("%Y-%m-%d %H:%M:%S"))
# 2018-09-03 10:14:53
# 2018-09-03 10:14:53
# 2018-09-03 10:14:53 #strptime(string[, format])
# 把一个格式化时间字符串转化为struct_time。实际上它和strftime()是逆操作。
# print(time.strptime('2018-09-03 10:14:53', '%Y-%m-%d %X'))
# time.struct_time(tm_year=2018, tm_mon=9, tm_mday=3, tm_hour=10, tm_min=14, tm_sec=53, tm_wday=0, tm_yday=246, tm_isdst=-1) #sleep(secs)
#time.sleep(10) #停止10秒,继续运行 # import datetime
# print(datetime.datetime.now())
# 2018-09-03 10:20:50.680030
python3.7 time模块的更多相关文章
- Python3之turtle模块的使用
Python3之turtle模块的使用 直接扣代码就行: import turtle as t t.pensize(4) t.hideturtle() t.colormode(255) t.c ...
- python基础系列教程——Python3.x标准模块库目录
python基础系列教程——Python3.x标准模块库目录 文本 string:通用字符串操作 re:正则表达式操作 difflib:差异计算工具 textwrap:文本填充 unicodedata ...
- Python3:Requests模块的异常值处理
Python3:Requests模块的异常值处理 用Python的requests模块进行爬虫时,一个简单高效的模块就是requests模块,利用get()或者post()函数,发送请求. 但是在真正 ...
- Python3中正则模块re.compile、re.match及re.search函数用法详解
Python3中正则模块re.compile.re.match及re.search函数用法 re模块 re.compile.re.match. re.search 正则匹配的时候,第一个字符是 r,表 ...
- Python3安装Celery模块后执行Celery命令报错
1 Python3安装Celery模块后执行Celery命令报错 pip3 install celery # 安装正常,但是执行celery 命令的时候提示没有_ssl模块什么的 手动在Python解 ...
- Python3之configparser模块
1. 简介 configparser用于配置文件解析,可以解析特定格式的配置文件,多数此类配置文件名格式为XXX.ini,例如mysql的配置文件.在python3.X中 模块名为configpars ...
- python3.7 os模块
#!/usr/bin/env python __author__ = "lrtao2010" #python3.7 os模块 #os模块是与操作系统交互的一个接口 # os.get ...
- python3.7 json模块
#!/usr/bin/env python __author__ = "lrtao2010" #python3.7 json模块 ''' 要在不同的编程语言之间传递对象,就必须把对 ...
- python3.7 random模块
#!/usr/bin/env python __author__ = "lrtao2010" #python3.7 random模块 import random #随机模块 # r ...
随机推荐
- IDEA右键新建时没有Java Class选项
今天在IDEA中新建了一个maven工程,但是在我想要新建Class时发件右键菜单里竟然没有Java Class选项!如下图所示: 如上图红圈所示,我们可以根据对项目的任意目录进行这五种目录类型标注, ...
- 常见的生成全局唯一id有哪些?他们各有什么优缺点?
分布式系统中全局唯一id是我们经常用到的,生成全局id方法由很多,我们选择的时候也比较纠结.每种方式都有各自的使用场景,如果我们熟悉各种方式及优缺点,使用的时候才会更方便.下面我们就一起来看一下常见的 ...
- hibernate课程 初探单表映射3-4 组件属性
本节内容: 1 简介组件属性 2 demo 1 简介组件属性: <component name = "address" class = "Address" ...
- 【Shell脚本学习24】Shell输入输出重定向:Shell Here Document,/dev/null文件
Unix 命令默认从标准输入设备(stdin)获取输入,将结果输出到标准输出设备(stdout)显示.一般情况下,标准输入设备就是键盘,标准输出设备就是终端,即显示器. 输出重定向 命令的输出不仅可以 ...
- C#调用Python脚本并使用Python的第三方模块
[转载]http://zh.5long.me/2015/dotnet-call-python/ 前言 InronPython是一种在.NET和Mono上实现的Python语言,使用InronPytho ...
- pta 编程题6 树的同构
其它pta数据结构编程题请参见:pta 题目请参见:树的同构 因题目中左右子树是按照下标给出,因此用数组存放树是更好的方法. 判断两棵树是否同构:用递归的方法.如果当前两个结点都为空,则返回TRUE: ...
- ES6中set和map的区别
Set ES6提供了新的数据结构Set.它类似于数组,但是成员的值都是唯一的,没有重复的值. Set函数可以接受一个数组(或类似数组的对象)作为参数,用来初始化. // 例一 var set = ne ...
- [转载]AngularJS入门教程04:双向绑定
在这一步你会增加一个让用户控制手机列表显示顺序的特性.动态排序可以这样实现,添加一个新的模型属性,把它和迭代器集成起来,然后让数据绑定完成剩下的事情. 请重置工作目录: git checkout -f ...
- 在编辑Spring的配置文件时的自动提示
打 开MyEclipse—>Windows--->referenecs——>General,选择下面的Keys,这就是快捷键的设 置,可将Content Assist的快捷键改为 A ...
- POJ-1274 The Perfect Stall---二分图模板
题目链接: https://vjudge.net/problem/POJ-1274 题目大意: 有n个奶牛和m个谷仓,现在每个奶牛有自己喜欢去的谷仓,并且它们只会去自己喜欢的谷仓吃东西,问最多有多少奶 ...