Python 时间处理---------笔记
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 时间处理---------笔记相关的知识,希望对你有一定的参考价值。
时区处理&格式化
import pytz from datetime import datetime # 设置时区 timezone = pytz.timezone(‘Asia/Shanghai‘) # 格式化 now_time = datetime.now(timezone).strftime("%Y-%m-%d %H:%M:%S") print(now_time)
直接输出当前时间戳
import time now_timestamps = time.time() print(now_timestamps)
datetime time 转换
import datetime import time import pytz str = ‘2016-10-26 23:12:19‘ str2datetime = datetime.datetime.strptime(str, ‘%Y-%m-%d %H:%M:%S‘) # print(str2datetime) datetime2str = str2datetime.strftime(‘%Y-%d-%m %H:%M:%S‘) # print(datetime2str) time_tuple = str2datetime.timetuple() # print(time_tuple) time2str = time.strftime("%Y-%m-%d %H:%M:%S", time_tuple) # print(time2str) tuple2datetime = datetime.datetime(*time_tuple[0:6]) # print(tuple2datetime) now_timestamps = time.time() # print(now_timestamps) time2datetime = datetime.datetime.fromtimestamp(now_timestamps) time_tuple = time.localtime(now_timestamps) print(time_tuple) #本地时区时间 local = datetime.datetime.fromtimestamp(now_timestamps) print(local) #标准时区时间 standard = datetime.datetime.utcfromtimestamp(now_timestamps) print(standard) #本地时区时间 local_tz = time.localtime(now_timestamps) print(local_tz) #标准时区时间 standard_tz = time.gmtime(now_timestamps) print(standard_tz)
以上是关于Python 时间处理---------笔记的主要内容,如果未能解决你的问题,请参考以下文章
编译原理构建一个简单的解释器(Let’s Build A Simple Interpreter. Part 7.)(笔记)解释器 interpreter 解析器 parser 抽象语法树AST(代码片