python日期时间转为字符串或者格式化输出的实例

yipeiwu_com6年前Python基础

如下所示:

年月日时分秒

>>> print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
2017-07-15 15:01:35

年月日 小时分钟

>>> print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
2017-07-15 15:01

年月日

>>> print datetime.datetime.now().strftime("%Y%m%d")
20170715

以上这篇python日期时间转为字符串或者格式化输出的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python 的类、继承和多态详解

类的定义 假如要定义一个类 Point,表示二维的坐标点: # point.py class Point: def __init__(self, x=0, y=0): s...

python学习笔记--将python源文件打包成exe文件(pyinstaller)

pyinstaller 库的使用 PyInstaller是一个十分有用的第三方库,它能够在Windows、Linux、Mac OS X 等操作系统下将 Python 源文件打包,通过对源...

《Python之禅》中对于Python编程过程中的一些建议

《Python之禅》中对于Python编程过程中的一些建议

围绕一门语言,学习它的文化精髓,能让你成为一名更优秀的程序员。如果你还没读过Python之禅(Zen of Python) ,那么打开Python的命令提示符输入import this,...

python3字符串操作总结

介绍Python常见的字符串处理方式 字符串截取 >>>s = 'hello' >>>s[0:3] 'he' >>>s[:...

Ruby元编程基础学习笔记整理

笔记一: 代码中包含变量,类和方法,统称为语言构建(language construct)。 # test.rb class Greeting def initialize(te...