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 pygame实现球球大作战

本文实例为大家分享了python pygame球球大作战的具体代码,供大家参考,具体内容如下 球球大作战:(大球吃小球,代码如下:) from random import randi...

python 定时器,轮询定时器的实例

python 定时器默认定时器只执行一次,第一个参数单位S,几秒后执行 import threading def fun_timer(): print('Hello Timer...

在python中实现强制关闭线程的示例

如下所示: import threading import time import inspect import ctypes def _async_raise(tid, exc...

python使用sqlite3时游标使用方法

cursor就是一个Cursor对象,这个cursor是一个实现了迭代器(def__iter__())和生成器(yield)的MySQLdb对象,这个时候cursor中还没有数据,只有等...

Pyinstaller 打包exe教程及问题解决

安装 pip insatll Pyinstaller 参数 pyinstaller -Fw main.py 参数 概述...