day18 time、datetime、calendar、sys、os、os.path模块
今日内容
时间模块
time
模块
datetime
模块
calendar
模块
系统模块
sys
模块
os
模块
os.path
模块
time
模块:
- 在
time
模块中使用最多的方法有:time()
:时间戳sleep()
:睡眠时间localtime()
:当前时区的当前时间gmtime()
:格林威治时区的当前时间strftime(自定义的格式)
: 把当前时间以自定义的时间显示出来
import time
print(time.time()) # 时间戳
time.sleep(3)
print(time.localtime()) # time.struct_time(tm_year=2019, tm_mon=5, tm_mday=7, tm_hour=20, tm_min=15, tm_sec=50, tm_wday=1, tm_yday=127, tm_isdst=0)
print(time.gmtime()) # time.struct_time(tm_year=2019, tm_mon=5, tm_mday=7, tm_hour=12, tm_min=15, tm_sec=50, tm_wday=1, tm_yday=127, tm_isdst=0)
# 使用strftime时,不同字母代表的意义 例如现在时间为2019年5月7日19点34分30秒 星期二
print(time.strftime("%y")) # 当前年份的简写 09
print(time.strftime("%Y")) # 当前年份的全写 2019
print(time.strftime("%m")) # 当前的月份 05
print(time.strftime("%d")) # 当前的日期 07
print(time.strftime("%D")) # 当前的日期 月/日/年 05/07/19
print(time.strftime("%h")) # 当前的月份 英文 May
print(time.strftime("%H")) # 当前的 时(24小时制) 19(点)
print(time.strftime("%I")) # 当前的 时(12小时制) 7(点)
# print(time.strftime("%i")) # 报错 ValueError: Invalid format string
print(time.strftime("%M")) # 当前的分钟 34(分)
# print(time.strftime("%s")) # ValueError: Invalid format string
print(time.strftime("%S")) # 当前的秒 30(秒)
print(time.strftime("%a")) # 当前星期几的缩写
print(time.strftime("%A")) # 当前星期几的全写
print(time.strftime("%x")) # 当前国外格式的日期 05/07/19
print(time.strftime("%X")) # 当前时间 20:06:22
print(time.strftime("%p")) # 当前时间是上午还是下午 AM / PM
总结:
1、对于格式化的格式,小时分钟秒 用的都是 大写
2、对于日期,用的全是小写 ,其中y的大写代表完整年份
3、常用的格式为:
print(time.strftime("%Y-%m-%d %H:%M:%S"))
2019-05-07 19:48:01
print(time.strftime("%Y-%m-%d %I:%M:%S" %p))
2019-05-07 07:48:01 PM
day18 time、datetime、calendar、sys、os、os.path模块的更多相关文章
- day17--模块之time、calendar、datetime、sys、os、os.path、json、pickle、random
一.时间模块(time,calendar,datetime) 在Python中,通常有这几种方式来表示时间: 时间戳(timestamp):通常来说,时间戳表示的是从1970年1月1日00:00:00 ...
- python常用模块:sys、os、path、setting、random、shutil
今日内容讲了3个常用模块 一.sys模块二.os模块三.os下path模块四.random模块五.shutil模块 一.sys模块 import sys #环境变量 print(sys.path) # ...
- 模块使用:time、datetime、calendar、sys、os、os.path、normcase和normapath、random、json、pickle
## time:时间 时间戳(timestamp):time.time() 延迟线程的运行:time.sleep(secs) (指定时间戳下的)当前时区时间:time.localtime([secs] ...
- 导包、时间模块【TIME、CALENDAR DATETIME】、SYS、OS, OS.PATH模块、项目开放周期&规范
导包 1.不考虑包的情况下直接from...直接导入文件夹下的具体模块 2. if __name__ == '__ma__' # 自执行 if __name__ == '模块名' # ...
- day18 时间:time:,日历:calendar,可以运算的时间:datatime,系统:sys, 操作系统:os,系统路径操作:os.path,跨文件夹移动文件,递归删除的思路,递归遍历打印目标路径中所有的txt文件,项目开发周期
复习 ''' 1.跨文件夹导包 - 不用考虑包的情况下直接导入文件夹(包)下的具体模块 2.__name__: py自执行 '__main__' | py被导入执行 '模块名' 3.包:一系列模块的集 ...
- Python自动化运维之9、模块之sys、os、hashlib、random、time&datetime、logging、subprocess
python模块 用一砣代码实现了某个功能的代码集合. 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用性和代码间的耦合.而对于一个复杂的功能来,可能需 ...
- Python 第五篇(上):算法、自定义模块、系统标准模块(time 、datetime 、random 、OS 、sys 、hashlib 、json和pickle)
一:算法回顾: 冒泡算法,也叫冒泡排序,其特点如下: 1.比较相邻的元素.如果第一个比第二个大,就交换他们两个. 2.对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对.在这一点,最后的元素应 ...
- Python (time、datetime、random、os、sys、shutil)模块的使用
######################################################### 模块time ################################### ...
- python内置模块[sys,os,os.path,stat]
python内置模块[sys,os,os.path,stat] 内置模块是python自带功能,在使用内置模块时,需要遵循 先导入在 使用 一.sys 对象 描述 sys.argv 命令行参数获取,返 ...
随机推荐
- TTTTTTTTTTTT Gym 100818B Tree of Almost Clean Money 树连剖分+BIT 模板题
Problem B Tree of Almost Clean Money Input File: B.in Output File: standard output Time Limit: 4 sec ...
- HGOI 20191103am 题解
Problem A number 使用一个$2^k$数集中每个元素的和表示数$n$,不同集合的数目有多少? 对于$100\%$的数据满足$1 \leq n \leq 10^6$ Solution : ...
- JavaWeb_(Hibernate框架)Hibernate论坛项目中一对多案例
基于SSH论坛小型项目 传送门 用户和发帖进行举例 一对多关系:一个用户可以发表多个帖子 一对一关系:一个帖子属于一个用户发布 创建数据库用户user表 CREATE TABLE `hforum`.` ...
- html,css,js实现的一个钟表
效果如图: 实现代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...
- Beta冲刺(1/4)
队名:福大帮 组长博客链接: https://www.cnblogs.com/mhq-mhq/p/11990568.html 作业博客 : https://edu.cnblogs.com/campus ...
- window 定时任务小项目,每秒钟,每分钟访问url
个人百度网盘中 链接: https://pan.baidu.com/s/15sK2H-OtrAkAYcXjsxwihA 提取码: awv3 复制这段内容后打开百度网盘手机App,操作更方便哦
- Video Captioning 综述
1.Unsupervised learning of video representations using LSTMs 方法:从先前的帧编码预测未来帧序列 相似于Sequence to sequen ...
- C++ STL——C++容器的共性和相关概念
目录 一 STL容器共性机制 二 STL容器的使用场合 三 函数对象 四 谓词 五 内建函数对象 六 函数对象适配器 注:原创不易,转载请务必注明原作者和出处,感谢支持! 注:内容来自某培训课程,不一 ...
- PCL中有哪些可用的PointT类型(2)
博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=267 PointXY-float x, y; 简单的二维x-y point结 ...
- [ML] Machine Learning in the Common Infrastructure ecosystem
一.CogNet架构 下图,可见Kafka的作用. Partial code: Machine Learning in the Common Infrastructure ecosystem Rele ...