#!/usr/bin/python3
# -*- coding: utf-8 -* import time def str_to_stamp():
# 转换显示格式
time1 = time.strptime(time_str, '%Y-%m-%d %H:%M:%S')
# 转为时间戳
time2 = int(time.mktime(time1))
print(time2) def stamp_to_str():
# 转换本地时间
time1 = time.localtime(time_stamp)
# 转为时间格式
time2 = time.strftime("%Y-%m-%d %H:%M:%S", time1)
print(time2) if __name__ == '__main__':
time_str = '2018-7-02 10:58:12'
time_stamp = 1530500292 str_to_stamp()
stamp_to_str()
相关文章
- python 字符串转时间戳datetime 以及儒略日的转换
- MicroPython: RTP同步时间和时间日期格式转换
- php时间戳秒和毫秒之间的区别和转换
- python爬虫:利用requests与json来爬取金十快讯时间与内容(对JavaScript格式数据处理转换成json格式数据)
- python中long类型的时间戳如何转换为日期格式
- Python - Excel - Matlab 时间戳的相互转换
- postgresql数据库的 to_date 和 to_timestamp 将 字符串转换为时间格式
- MySQL 日期和时间戳的转换 | 以及DATE_FORMAT()用法
- mysql—MySQL数据库中10位或13位时间戳和标准时间相互转换
- Oracle数据库中的时间格式和java中时间格式的转换