python中strftime和strptime函数
strftime和strptime函数均来自包datetime
from datetime import *
strftime:
将datetime包中的datetime类,按照入参格式生成字符串变量
from datetime import *
currenttime=datetime.now() #生成当前时间的datetime类实例
print('type of currenttime', type(currenttime))
print(currenttime)
cur=currenttime.strftime('%Y_%m_%d-%H-%M-%S')
print('type of cur', type(cur))
print(cur)
输出
type of currenttime <class 'datetime.datetime'>
2019-08-29 14:01:39.973547
type of cur <class 'str'>
2019_08_29-14-01-39
strptime:
将字符串根据其格式,提取所含时间,并生成datetime类实例
from datetime import *
strdate='2019:08:29:09-00-00'
strdatetime=datetime.strptime(strdate,'%Y:%m:%d:%H-%M-%S')
print('type of strdatetime:',type(strdatetime),':',strdatetime)
输出
type of strdatetime: <class 'datetime.datetime'> : 2019-08-29 09:00:00
注意:strptime中的第二个参数是输入字符串的格式,而不是出参格式,datetime实例的格式是固定的
python中strftime和strptime函数的更多相关文章
- Python 函数式编程 & Python中的高阶函数map reduce filter 和sorted
1. 函数式编程 1)概念 函数式编程是一种编程模型,他将计算机运算看做是数学中函数的计算,并且避免了状态以及变量的概念.wiki 我们知道,对象是面向对象的第一型,那么函数式编程也是一样,函数是函数 ...
- Python中的高阶函数与匿名函数
Python中的高阶函数与匿名函数 高阶函数 高阶函数就是把函数当做参数传递的一种函数.其与C#中的委托有点相似,个人认为. def add(x,y,f): return f( x)+ f( y) p ...
- python中enumerate()函数用法
python中enumerate()函数用法 先出一个题目:1.有一 list= [1, 2, 3, 4, 5, 6] 请打印输出:0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 打印输 ...
- Python中str()与repr()函数的区别——repr() 的输出追求明确性,除了对象内容,还需要展示出对象的数据类型信息,适合开发和调试阶段使用
Python中str()与repr()函数的区别 from:https://www.jianshu.com/p/2a41315ca47e 在 Python 中要将某一类型的变量或者常量转换为字符串对象 ...
- Python中sort和sorted函数代码解析
Python中sort和sorted函数代码解析 本文研究的主要是Python中sort和sorted函数的相关内容,具体如下. 一.sort函数 sort函数是序列的内部函数 函数原型: L.sor ...
- Python中进制转换函数的使用
Python中进制转换函数的使用 关于Python中几个进制转换的函数使用方法,做一个简单的使用方法的介绍,我们常用的进制转换函数常用的就是int()(其他进制转换到十进制).bin()(十进制转换到 ...
- Python中的内置函数
2.1 Built-in Functions The Python interpreter has a number of functions built into it that are alway ...
- Python中str()与repr()函数的区别
在 Python 中要将某一类型的变量或者常量转换为字符串对象通常有两种方法,即str()或者 repr() . >>> a = 10 >>> type(str(a ...
- python中os.path.isdir()函数的使用
在python 中,os.path.isdir(path)函数主要用来判断函数内部的path是否为一个目录 具体关于这个函数的解说参考博客https://blog.csdn.net/xjp_xujip ...
随机推荐
- AAAI 2018 分析
AAAI 2018 分析 word embedding Learning Sentiment-Specific Word Embedding via Global Sentiment Represen ...
- python语言优势
与Java等语言比较起来,最大优点是语法很简洁,很多功能像octave和matlab,能够对数组或矩阵进行高效处理. 比如一个数组求和,这里只要一句话sum(a),Java等语言就需要循环.还有矩阵的 ...
- mysql数据库连接错误10060
今天在使用mysql数据库的时候,出现错误ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10060) 我在网上一顿 ...
- 安装golang web框架 gin
gin 地址https://github.com/gin-gonic/gin#installation 去gin 地址 clone 下来,放到对应的包中即可.如:gin就放在项目文件夹/github. ...
- OutLook会议室预定提醒
项目组采用敏捷开发管理,每两周一个迭代.写个工具做会议室预定. 代码下载:https://download.csdn.net/download/linmilove/10547579 Appointme ...
- 爬虫二之Requests
requests 实例引入 import requests response = requests.get('https://www.baidu.com') response.status_code ...
- (转载)gcc编译选项总结
转载自:https://blog.csdn.net/gatieme/article/details/21389603 常用编译选项 gcc and g++分别是gnu的c & c++编译器 g ...
- 如何学习MySQL数据库管理员(OCP)认证(转)
如何学习MySQL数据库管理员(OCP)认证 转自: 甲骨文专家中,MySQL 5.6数据库管理员( OCP )证明您的安装和优化MySQL服务器,设置复制和安全,执行数据库备份及性能优化和保护M ...
- Linux命令学习(0)
作为一名前端,可能接触到linux的机会并不多,但这不代表就不需要学.对我而言,学习linux主要是为了方便部署我的项目到服务器,我并没有花时间去学这些,只是上网查怎么部署项目,然后按教程一步一步来, ...
- qt QUndoGroup的使用
最近项目中用到撤销,恢复功能.qt的demo中有一个例子,是类似于单文档的.而我的项目中是类似于多文档的项目,即可能要打开多个页面,不同的页面都有撤销恢复功能.这样的话,就要用到QUndoGroup类 ...