Python datetime时间格式化去掉前导0

yipeiwu_com6年前Python基础

Python时间格式化的时候,去掉前导0的:

dt = datetime.now() 
print dt.strftime('%-H')

#结果是: '4'

在format string的%与flag之间,添加一个“-”即可。

在Mac和Linux中试过可用,不确定是否可以移植。

相关文章

python处理csv中的空值方法

如下所示: # -*- coding: UTF-8 -*- import jieba.posseg import tensorflow as tf import pandas as...

梅尔倒谱系数(MFCC)实现

本文实例为大家分享了梅尔倒谱系数实现代码,供大家参考,具体内容如下 """ @author: zoutai @file: mymfcc.py @time: 2018/03/26...

Python multiprocess pool模块报错pickling error问题解决方法分析

本文实例讲述了Python multiprocess pool模块报错pickling error问题解决方法。分享给大家供大家参考,具体如下: 问题 之前在调用class内的函数用mu...

Python中文件的写入读取以及附加文字方法

今天学习到python的读取文件部分。 还是以一段代码为例: filename='programming.txt' with open(filename,'w') as file_o...

Python 使用type来定义类的实现

Python 使用type来定义类的实现

我们先来看一张图 仔细观察: 我们使用 class 定义了 Class类,然后实例化给 cls 观察cls的类型,它的类型指向 Class 那么Class的类型指向谁呢?指向type...