文章详情页
基于python获取本地时间并转换时间戳和日期格式
浏览:41日期:2022-07-07 08:59:24
附上代码与运行结果截图:
import time# 获取当前时间now = time.localtime()# 格式化日期now_ = time.strftime(’%Y-%m-%d %H:%M:%S’, now)# 获取当前时间,以时间戳格式now_stamp = time.time()# 日期转时间戳change_to_stamp = time.mktime(time.strptime(now_, '%Y-%m-%d %H:%M:%S'))# 时间戳转日期change_to_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(now_stamp))print(now)print(now_)print(now_stamp)print(change_to_stamp)print(change_to_time)
运行截图如下:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持好吧啦网。
相关文章:
1. IntelliJ IDEA设置自动提示功能快捷键的方法2. 使用Python webdriver图书馆抢座自动预约的正确方法3. ASP.NET MVC使用jQuery ui的progressbar实现进度条4. 从Python的字符串中剥离所有非数字字符(“。”除外)5. 在线php代码缩进、代码美化工具:PHP Formatter6. PHP如何开启Opcache功能提升程序处理效率7. Python3 json模块之编码解码方法讲解8. SpringBoot整合Redis的步骤9. PHP程序员简单的开展服务治理架构操作详解(二)10. 详解如何使用Net将HTML简历导出为PDF格式
排行榜

网公网安备