1. 时间戳转日期

  • 代码
import time
timestamp = 1568171336
time_format = "%Y-%m-%d %H:%M:%S"
time_local = time.localtime(timestamp)
new_date = time.strftime(time_format, time_local)
print(new_date)
  • 结果
2019-09-11 11:08:56

2. 不自动补零

对于Linux 需要在字段类型前加上 -

对于win 需要再字段类型前加上 #

  • 代码示例
import time
timestamp = 1568171336
time_format = "%Y-%#m-%#d %H:%M:%S"
time_local = time.localtime(timestamp)
new_date = time.strftime(time_format, time_local)
print(new_date)
  • 结果
2019-9-11 11:08:56

来自 Python datetime formatting without zero-padding

Accepted answer not a proper solution (IMHO) The proper documented methods:

In Linux "#" is replaced by "-":

%-d, %-H, %-I, %-j, %-m, %-M, %-S, %-U, %-w, %-W, %-y, %-Y

In Windows "-" is replaced by "#":

%#d, %#H, %#I, %#j, %#m, %#M, %#S, %#U, %#w, %#W, %#y, %#Y

  • Linux
mydatetime.strftime('%-m/%d/%Y %-I:%M%p')
  • Windows
mydatetime.strftime('%#m/%d/%Y %#I:%M%p')

最新文章

  1. Login控件尝试
  2. iOS 含有 中文的URL 转码问题
  3. Android端百度地图API使用详解
  4. selenium在chrome上运行报 Element is not clickable at point (1096, 26)
  5. 【转】MyBatis学习总结(七)——Mybatis缓存
  6. Java学习----集合函数
  7. Jenkins api java 调用
  8. [php基础]PHP.INI配置:文件上传功能配置教程
  9. Bug解决过程复盘
  10. 【Java】ArrayList 的 toArray() 方法抛出 ClassCastException 异常
  11. spring容器启动的加载过程(三)
  12. 团队项目汇总beta
  13. Python:list 和 array的对比以及转换时的注意事项
  14. angular4.0运行在微信端的坑坑洼洼
  15. 富文本框vue-quill-editor的使用
  16. iOS ReplayKit 录屏 框架的使用
  17. Windows 7 编译64位boost库
  18. RabbitMq中的消息应答与持久化
  19. 【PowerDesigner】【1】简单介绍
  20. [C/C++] 字符串错题集

热门文章

  1. K8S-PV和PVC
  2. pj_0002_wbs_manager
  3. ApexSQLDBA 2019.02.1245[破解补丁]
  4. 【java数据结构与算法】选择排序
  5. MyBatis_10(分页插件)
  6. python34
  7. window向linux传递文件
  8. 《Vue.js 3.x高效前端开发(视频教学版)》简介
  9. JavaScript的原型和原型链
  10. 解决QtCreator运行程序报plugin xcb的错误