Python datetime __str __()方法与示例
Python datetime .__ str __()方法 (Python datetime.__str__() Method)
datetime.__str__() method is used to manipulate objects of datetime class of module datetime.
datetime .__ str __()方法用于操作模块datetime的datetime类的对象。
It uses a datetime class object and returns a string representation of the object. For a datetime object d, str(d) is equivalent to d.isoformat(' '). str() is an instance method as it uses an instance of the class.
它使用日期时间类对象,并返回该对象的字符串表示形式。 对于日期时间对象d , str(d)等效于d.isoformat('')。 str()是一个实例方法,因为它使用类的实例。
Module:
模块:
import datetime
Class:
类:
from datetime import datetime
Syntax:
句法:
str()
Parameter(s):
参数:
None
没有
Return value:
返回值:
The return type of this method is a string representing the original datetime object.
此方法的返回类型是代表原始datetime对象的字符串。
Example:
例:
## importing datetime class
from datetime import datetime
import pytz
## Creating an instance
x = datetime.now()
d = str(x)
print("Original object:",x)
print("Date String:", d)
print()
## str function also uses the ISO format
x = datetime(2020, 1, 27, 23, 12, 24, 4566)
print("Date string of date 2020/1/27 and time 23:12:24 :", str(x))
print()
x = datetime(200, 1, 2, 3, 12, 24, 4566)
timezone = pytz.timezone('Asia/Tokyo')
x = x.astimezone(timezone)
print("Date string of date 200/1/2 and time 3:12:24 with tzinfo present :", str(x))
print()
## str(x) is equivalent to x.isoformat() function
x = datetime(200,10,12)
print("Datetime in ISO 8601 format using isoformat() function:", x.isoformat(' '))
print("Date string 200/10/12 using str() function:", str(x))
print( x.isoformat(' ') == str(x))
Output
输出量
Original object: 2020-05-03 16:45:16.315525
Date String: 2020-05-03 16:45:16.315525
Date string of date 2020/1/27 and time 23:12:24 : 2020-01-27 23:12:24.004566
Date string of date 200/1/2 and time 3:12:24 with tzinfo present : 0200-01-02 12:31:24.004566+09:19
Datetime in ISO 8601 format using isoformat() function: 0200-10-12 00:00:00
Date string 200/10/12 using str() function: 0200-10-12 00:00:00
True
翻译自: https://www.includehelp.com/python/datetime-__str__-method-with-example.aspx
Python datetime __str __()方法与示例相关推荐
- python文件的用法,Python 文件 readlines() 使用方法及示例
Python 文件 readlines() 使用方法及示例 概述 readlines() 方法用于读取所有行(直到结束符 EOF)并返回列表,该列表可以由 Python 的 for... in ... ...
- python datetime模块-Python datetime模块使用方法小结
datetime模块 当前日期 datetime.date.today() datetime.date(2020, 4, 24) 转换元祖 >>> datetime.date.tim ...
- lock_sh 示例_带有示例的Python date __str __()方法
lock_sh 示例 Python date .__ str __()方法 (Python date.__str__() Method) date.__str__() method is used t ...
- python dateformatter_Python dates.DateFormatter方法代码示例
本文整理汇总了Python中matplotlib.dates.DateFormatter方法的典型用法代码示例.如果您正苦于以下问题:Python dates.DateFormatter方法的具体用法 ...
- python pool_Python pool.Pool方法代码示例
本文整理汇总了Python中multiprocessing.pool.Pool方法的典型用法代码示例.如果您正苦于以下问题:Python pool.Pool方法的具体用法?Python pool.Po ...
- python info_Python logger.info方法代码示例
本文整理汇总了Python中utils.logger.info方法的典型用法代码示例.如果您正苦于以下问题:Python logger.info方法的具体用法?Python logger.info怎么 ...
- python paperclip_Python pyplot.sca方法代码示例
本文整理汇总了Python中matplotlib.pyplot.sca方法的典型用法代码示例.如果您正苦于以下问题:Python pyplot.sca方法的具体用法?Python pyplot.sca ...
- python fonttool_Python wx.Font方法代码示例
本文整理汇总了Python中wx.Font方法的典型用法代码示例.如果您正苦于以下问题:Python wx.Font方法的具体用法?Python wx.Font怎么用?Python wx.Font使用 ...
- python res_Python models.resnet152方法代码示例
本文整理汇总了Python中torchvision.models.resnet152方法的典型用法代码示例.如果您正苦于以下问题:Python models.resnet152方法的具体用法?Pyth ...
最新文章
- 组建一台计算机3_硬件3 多位运算器
- 如何读懂UWA性能报告?—NGUI篇
- 【ESSD技术解读】 云原生时代,阿里云块存储 ESSD 快照服务如何被企业级数据保护所集成?
- 使用 ASP.NET Core, Entity Framework Core 和 ABP 创建N层Web应用 第二篇
- STM32的SRAM调试
- 【Es】ElasticSearch 自定义分词器
- 想要轻松入门数据分析,这些知识不得不看!
- 「大学生学编程系列」第六篇:如何学习C语言?
- 如何做好Web接口测试
- [bzoj4826][Hnoi2017]影魔
- IFC标准是什么标准?IFC标准的发展历程是怎样的?
- 超全超详细的安装nvidia显卡驱动教程
- 算法与数据结构学习路线
- 【kettle抽取Orecle/Mysql数据至HDFS】诸如‘\u0001’等特殊分隔符表示法
- api 接口响应数据格式有哪些
- 评测i9 13900hx和​​R9 7940HS选哪个 酷睿i913900hx和​​锐龙R97940HS对比
- MySQL如何修改主键
- Unity最简单的消息中心
- Java线程安全的实现方法
- 通联支付(POS机支付功能)
热门文章
- 2020年最快的dns_2020年哪里换旅行证最快取证?需要几天?
- AttributeError: 'NoneType' object has no attribute 'astype'
- JDK源码解析之 java.lang.ClassLoader
- JAVA知识基础(一):数据类型
- 问题 A: 深度学习
- Linux的标准I/O和管道
- 记一次,jvm 内存溢出
- 一些adb的常用命令
- 学生机房虚拟化(十)系统操作设计实现
- 【iCore4 双核心板_FPGA】例程十六:基于双口RAM的ARM+FPGA数据存取实验