Python strftime-日期前无0? [英] Python strftime - date without leading 0?

查看:255
本文介绍了Python strftime-日期前无0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Python strftime时,有一种方法可以删除日期的第一个0(如果它在10之前),即.所以011吗?找不到%东西吗?

谢谢!

解决方案

实际上,我遇到了同样的问题,并且我意识到,如果在%和字母之间添加连字符,则可以删除前导零. /p>

例如%Y/%-m/%-d.

这仅适用于Unix(Linux,OS X),而不适用于Windows(包括Cygwin).在Windows上,您可以使用#,例如%Y/%#m/%#d.

When using Python strftime, is there a way to remove the first 0 of the date if it's before the 10th, ie. so 01 is 1? Can't find a %thingy for that?

Thanks!

解决方案

Actually I had the same problem and I realized that, if you add a hyphen between the % and the letter, you can remove the leading zero.

For example %Y/%-m/%-d.

This only works on Unix (Linux, OS X), not Windows (including Cygwin). On Windows, you would use #, e.g. %Y/%#m/%#d.

这篇关于Python strftime-日期前无0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆