文章目录
sys模块
sys模块的使用
sys.getdefaultencoding()——获取系统当前的编码
sys.path——返回环境变量的路径,跟解释器有关
sys.platform——返回当前系统平台
sys.version——查看目前系统python的版本
代码演示
导入模块:import sys

time模块
time.time():获取时间戳
时间戳:表示从1970年1月1日00:00:00开始到现在按秒计算的偏移量。

time.localtime():获取一个struct_time对象

struct_time对象各个元素说明
tm_year:年
tm.mon:月(1-12)
tm_mday:日(1-31)
tm_hour:时(0-23)
tm_min:分(0-59)
tm.sec:秒(0-59)
tm_wday:星期几(0-6,0表示周日)
tm_yday:一年中的第几天(1-366)
tm_isdst:是否是夏令时(默认是-1)
time.asctime()

time.strftime(格式化字符串,struct_time对象)
- 将struct_time转换成字符串

time.strptime():将时间字符串转换成struct_time对象

Python编程:sys与time模块详解
本文详细介绍了Python中的sys模块,包括sys.getdefaultencoding()、sys.path和sys.platform等方法的使用。同时,文章也探讨了time模块,讲解了time.time()获取时间戳、time.localtime()转换为struct_time对象以及struct_time对象的各个元素。此外,还介绍了time.asctime()和time.strftime()、time.strptime()函数用于时间字符串的转换。
393

被折叠的 条评论
为什么被折叠?



