[Python]Python日期格式和字符串格式相互转换
2023-02-18 15:41:17 时间
由字符串格式转化为日期格式的函数为: datetime.datetime.strptime()
由日期格式转化为字符串格式的函数为: datetime.datetime.strftime()
# encoding: utf-8 import datetime day = datetime.datetime.strptime('2020-2-18 10:54:45', '%Y-%m-%d %H:%M:%S') print(day) print type(day) day = datetime.datetime.strftime(day, '%Y-%m-%d %H:%M:%S') print(day) print type(day)
root@tao:/var/www/html/python# python 3.py
2020-02-18 10:54:45
<type 'datetime.datetime'>
2020-02-18 10:54:45
<type 'str'>
相关文章
- [Python] 函数基本
- [Python] 使用dict和set
- [Python] Python基础字符串
- Python 绑定:从 Python 调用 C 或 C++
- Python 没有函数重载?如何用装饰器实现函数重载?
- [oeasy]python0028_直接运行_修改py文件执行权限_设置py文件打开方式
- 这15个顶级Python库,你必须要试试!
- ikun必学!python 画一个简单的只因
- 技术实践:教你用Python搭建gRPC服务
- 带你掌握4种Python 排序算法
- 一文讲全了Python 类和对象内容
- 什么是Python中的套接字编程?
- [Python]介绍
- [Python]第一章(建议收藏)
- 【Python】第二章(条件语句和循环语句)
- [Python]第三章(字符串) ---【建议收藏】
- (一)Python基本语法元素
- (二)Python基础结构
- (四)Python: NumPy中的ndarry
- (五)Python:Pandas中的Series