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

yipeiwu_com5年前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 用下标截取字符串的实例

运行环境: win7 64位 python 2.7 pycharm python 源码如下 # -*- coding: utf-8 -*- str = '0123456789'...

python中的for循环

python中的for循环

Python for循环可以遍历任何序列的项目,如一个列表或者一个字符串。 语法: for循环的语法格式如下: for iterating_var in sequence:...

Python中请使用isinstance()判断变量类型

一、isinstance() 在Python中可以使用type()与isinstance()这两个函数判断对象类型,而isinstance()函数的使用上比type更加方便。 复制代码...

Matplotlib 生成不同大小的subplots实例

Matplotlib 生成不同大小的subplots实例

在Matplotlib实际使用中会有生成不同大小subplots的需求。 import numpy as np import matplotlib.pyplot as plt f...

python统计文本文件内单词数量的方法

本文实例讲述了python统计文本文件内单词数量的方法。分享给大家供大家参考。具体实现方法如下: # count lines, sentences, and words of a t...