python 时间戳转日期 不自动补零 without zero-padding
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的更多相关文章
- Python时间戳和日期的相互转换
Python时间戳和日期的相互转换 (2014-03-17 11:24:35) 转载▼ 分类: Python 当前时间戳:time.time() 当前日期:time.ctime() 1.Pytho ...
- 【c++基础】int转string自动补零
前言 使用to_string函数可以将不同类型的数据转换为string类,请参考here和here.如果string的位数固定,如何进行自动补零呢?请看本文实例! 代码 确定位数,to_string ...
- Java中在数字前自动补零方法
/** * 数字前面自动补零 * @param number 数字 * @return */ public static String geFourNumber(int number){ Number ...
- js正则格式化日期时间自动补0
原文 js正则格式化日期时间自动补0 背景 时间日期格式化的需求很常见,也有很多工具类转换方法,比如需要将2022-3-4这种日期格式转化为2022-03-04,也就是实现个位数月份或天数日期自动前置 ...
- Python 在 Terminal 中的自动补全
为了在 Terminal 中使用 Python 更加方便,在 home 目录下添加脚本 .pythonstartup,内容如下, 然后在 .bashrc 中添加 export PYTHONSTARTU ...
- Python交互模式下代码自动补全
这个功能是以lib的形式提供的,配置写到home下的.pythonrc文件中, 并设置好环境变量让python启动时执行初始化: # ~/.pythonrc # enable syntax compl ...
- 在Python命令行和VIM中自动补全
作者:gnuhpc 出处:http://www.cnblogs.com/gnuhpc/ 1. VIM下的配置: wget https://github.com/rkulla/pydiction/arc ...
- java 数字前自动补零实现
/** * 里数字转字符串前面自动补0的实现. * */ public class TestStringFormat { public static void main(String[] args) ...
- python机器学习实现人脸图片自动补全
人脸自动补全 关注公众号"轻松学编程"了解更多. 1.导包 import matplotlib.pyplot as plt import numpy as np import pa ...
- python数字前自动补零
>>> '%d' % 23 #输出23 ' >>> '%5d' % 23 #输出的数字前有3个空位,共占5个字符 ' >>> '%05d' % 2 ...
随机推荐
- pillow 创建图片并添加一些自定义信息
from PIL import Image vm = Image.new('RGBA', (dshape[1], dshape[0])) vm = Image.fromarray(np.array(s ...
- 2023 01 19 HW
2023 01 19 HW Okay, then let's start. Okay. Maybe Karina, we start with the C2 design freeze. Yeah, ...
- firefox 安装旧版flash播放器
国内恶心的特供版flash用是不可能在用了,用旧版的火狐和旧版的flash播放器,亲测可用. 下载旧版本的火狐浏览器67.04 https://ftp.mozilla.org/pub/firefox/ ...
- VS2019+ Intel Fortran (oneAPI)+HDF5库的安装+测试
最近需要读取hdf5文件(*.h5),处于对速度的追求,兼具VS调试程序的需要,使用Fortran+HDF5进行读写. 注意: 此处为动态库连接方式,静态库类似,差异主要为头文件有所差异. 参考网址: ...
- Zookeeper ZAB协议-Leader&Followe 对象创建和启动源码解析
这篇博客主要是解析了Leader,Follower 对象的创建,相对来说比较简单,主要是了解一下在实例化的时候创建了哪些对象,这些对象会在数据传输的过程中发挥比较打的作用,如果有了解过的,可以直接跳过 ...
- fastapi四:uvicorn.run支持的参数
`app:指定应用app,'脚本名:FastAPI实例对象'.FastAPI实例对象 host: 字符串,允许被访问的形式 locahost.127.0.0.1.当前IP.0.0.0.0,默认为127 ...
- ssh 免密访问
首先配置三台机器的hosts文件 填写需要配置的三台主机ip,然后命名,这里我写的时 t1 t2 t3 三台机器上都要配置hosts文件,要配置一样. 三台机器改完后保存退出 ping一下刚才配置的三 ...
- php 图片加水印插件
问题:背景透明的水印图片,在加到原图上后不显示,待解决 <?php /** * 图片加水印(适用于png/jpg/gif格式) * * @author flynetcn * * @param $ ...
- 关于sql时间方面的处理
查询大于时间两小时(例:订单设置两小时后过期 $res = Order::where(['status'=>0,'sid'=>1])->whereRaw("created_ ...
- select标签如何实现 每个option传递多个值
设计项目时 我们有时候会利用 <select> <option value="值1" > </option> </select> ...