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')

python 时间戳转日期 不自动补零 without zero-padding的更多相关文章

  1. Python时间戳和日期的相互转换

    Python时间戳和日期的相互转换 (2014-03-17 11:24:35) 转载▼   分类: Python 当前时间戳:time.time() 当前日期:time.ctime() 1.Pytho ...

  2. 【c++基础】int转string自动补零

    前言 使用to_string函数可以将不同类型的数据转换为string类,请参考here和here.如果string的位数固定,如何进行自动补零呢?请看本文实例! 代码 确定位数,to_string ...

  3. Java中在数字前自动补零方法

    /** * 数字前面自动补零 * @param number 数字 * @return */ public static String geFourNumber(int number){ Number ...

  4. js正则格式化日期时间自动补0

    原文 js正则格式化日期时间自动补0 背景 时间日期格式化的需求很常见,也有很多工具类转换方法,比如需要将2022-3-4这种日期格式转化为2022-03-04,也就是实现个位数月份或天数日期自动前置 ...

  5. Python 在 Terminal 中的自动补全

    为了在 Terminal 中使用 Python 更加方便,在 home 目录下添加脚本 .pythonstartup,内容如下, 然后在 .bashrc 中添加 export PYTHONSTARTU ...

  6. Python交互模式下代码自动补全

    这个功能是以lib的形式提供的,配置写到home下的.pythonrc文件中, 并设置好环境变量让python启动时执行初始化: # ~/.pythonrc # enable syntax compl ...

  7. 在Python命令行和VIM中自动补全

    作者:gnuhpc 出处:http://www.cnblogs.com/gnuhpc/ 1. VIM下的配置: wget https://github.com/rkulla/pydiction/arc ...

  8. java 数字前自动补零实现

    /** * 里数字转字符串前面自动补0的实现. * */ public class TestStringFormat { public static void main(String[] args) ...

  9. python机器学习实现人脸图片自动补全

    人脸自动补全 关注公众号"轻松学编程"了解更多. 1.导包 import matplotlib.pyplot as plt import numpy as np import pa ...

  10. python数字前自动补零

    >>> '%d' % 23 #输出23 ' >>> '%5d' % 23 #输出的数字前有3个空位,共占5个字符 ' >>> '%05d' % 2 ...

随机推荐

  1. Install Argo Workflows

    Install Argo Workflows Release v3.4.3 · argoproj/argo-workflows (github.com) CLI # Download the bina ...

  2. 蓝牙信标、智能楼宇应用国产低功耗芯片BLE5.2 PHY6252

    PHY6252是一款支持BLE 5.2功能的系统级芯片(SoC),集成了低功耗的高性能多模射频收发机,搭载32位高性能低功耗处理器,提供64K retention SRAM.可选512/256K Fl ...

  3. excel数字转日期

    import datetime delta = datetime.timedelta() today = datetime.datetime.strptime('1899/12/30', '%Y/%m ...

  4. csp2020——T3表达式

    后缀表达式基本可以使用栈来表达,所以30分的暴力做法很好做 正解的做法是: 暴力的做法是每次重新建立栈,用符号来把栈顶的元素弹出来,做完运算之后再放入栈中,如果是与运算,弹出两个元素,如果是或运算,弹 ...

  5. win10 蓝屏代码 IRQL NOT LESS OR EQUAL 问题排查(ing)

    环境:Win10故障症状: 不定期蓝屏,重启 蓝屏代码: IRQL NOT LESS OR EQUAL 官方建议 尝试方法1:更新win10最新的补丁 [无效] 尝试方法2:重新安装显卡驱动(当前系统 ...

  6. Jupyter Notebook安装代码提示功能

    默认Jupyter Notebook没有安装代码提示功能,但是我们可以可通过如下命令安装和配置使得Jupyter Notebook具备代码提供功能. (确保Anaconda在环境变量里)1.电脑上搜索 ...

  7. ICPC2020 沈阳

    F-Kobolds and Catacombs 牛客网 题意:对于\(n(n<=10^6)\)个数的序列,划分区间,每个区间内部从小到大排序,要求最后整个序列单调不下降,求最多可以划分为多少个区 ...

  8. vant-ui经验

    1.van-checkbox搭配van-cell使用,点击圆圈区域,不触发定义的click函数. 解决:给van-checkbox添加一层div,添加click事件:van-checkbox也添加cl ...

  9. Oracle 低版本客户端连接19C报错ORA-28040

    # 适用范围12.2+# 问题概述客户使用Oracle11.2客户端连接Oracle 19c的时候,报错: ORA-28040: No matching authentication protocol ...

  10. SAP 结构转JSON

    *使用方式 jsonstr = zui2_json=>serialize( data = ls_in compress = abap_true pretty_name = zui2_json=& ...