Python datetime time()方法与示例

news/2025/2/19 10:20:07

Python datetime.time()方法 (Python datetime.time() Method)

datetime.time() method is used to manipulate objects of datetime class of module datetime.

datetime.time()方法用于操作模块datetime的datetime类的对象。

It uses an instance method and converts it and returns a time object with the same hour, minute, second, microsecond, and fold. tzinfo is None for this method.

它使用实例方法进行转换,并返回具有相同时,分,秒,微秒和倍数的时间对象。 tzinfo对于此方法为None。

Module:

模块:

    import datetime

Class:

类:

    from datetime import datetime

Syntax:

句法:

    time()

Parameter(s):

参数:

  • None

    没有

Return value:

返回值:

The return type of this method is a time object with same hour, minute, second, microsecond and fold. tzinfo is None.

此方法的返回类型是具有相同时,分,秒,微秒和倍数的时间对象。 tzinfo为“无”。

Example:

例:

## Creating a time object from a datetime object
from datetime import datetime
import pytz

## Creating datetime instance
x = datetime(2020, 3, 4,23,12,23,44)
d = x.time()
print("Original object:", x)
print("New time object:",d)
print()

x = datetime.now()
d = x.time()
print("Original date and time", x)
print("New time objec:", d)
print()

x = datetime.today()
d = x.time()
print("Printing the same")
print(x)
print(d)
print()

t = pytz.timezone("Asia/Kolkata")
## Adding tzinfo
x = x.astimezone(t)
d = x.time()
## Note: tzinfo is also not added in the object
## therefor giving a naive time object
print(x)
print(d)

Output

输出量

Original object: 2020-03-04 23:12:23.000044
New time object: 23:12:23.000044

Original date and time 2020-05-03 18:05:23.458667
New time objec: 18:05:23.458667

Printing the same
2020-05-03 18:05:23.458730
18:05:23.458730

2020-05-03 23:35:23.458730+05:30
23:35:23.458730


翻译自: https://www.includehelp.com/python/datetime-time-method-with-example.aspx

文章来源:https://blog.csdn.net/cumtb2009/article/details/107765551
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.niftyadmin.cn/n/1254517.html

相关文章

生活中的算法的实际举例_c语言,c语言算法,简单算法举例说明以及算法都包含哪些特性...

什么是算法?做任何事情都有一定的步骤。例如,你想从北京去香港开会,首先要去买飞机票,然后按时乘坐地铁达到机场,登上飞机,下飞机后打的去往会议目的地,参加会议。要考大学,首先要填…

python线程同步锁_Python实现的多线程同步与互斥锁功能示例

本文实例讲述了Python实现的多线程同步与互斥锁功能。分享给大家供大家参考,具体如下:#! /usr/bin/env python#codingutf-8import threadingimport time#1、不加锁num 0class MyThread(threading.Thread):def run(self):global numtime.sleep(1) #一定要…

如何查看域控计算机是哪个用户登陆,查看域控制器上登录用户

如何查看当前域控登录验证的用户?域内多台域控制器,如何查看某台域控制器上当前登录的用户或计算机?系统自动的工具好像没有实现此需求的办法,有无像脚本或者其他的思路来满足此需求呢?是指验证过的用户或计算机对象。…

strictmath_Java StrictMath cosh()方法与示例

strictmathStrictMath类cosh()方法 (StrictMath Class cosh() method) cosh() method is available in java.lang package. cosh()方法在java.lang包中可用。 cosh() method is used to return the hyperbolic cosine of an angle of the given parameter in the method. Here,…

城轨里面跟计算机相关的工作,城轨控制专业计算机能力培养和课程整合研究.doc...

城轨控制专业计算机能力培养和课程整合研究城轨控制专业计算机能力培养和课程整合研究摘要:通过对城轨控制专业岗位技能及典型工作任务的分析和研究,找出专业技能与计算机技能的对接点,在深入分析该专业所需计算机能力的基础上,设…

python ndarray转换为array_python – 如何将numpy.recarray转换为numpy.array?

通过“正常数组”我认为你是一个NumPy数组的均匀dtype.给予重新记录,如:>>> a np.array([(0, 1, 2),(3, 4, 5)],[(x, int), (y, float), (z, int)]).view(np.recarray)rec.array([(0, 1.0, 2), (3, 4.0, 5)],dtype[(x, 我们必须先使每一列具有相同的dtype…

职业等级计算机操作员,计算机操作员是什么职业?

职业概况:1、职业名称:计算机操作员2、职业定义:使用电子计算机微机从事文字、图形、图像等信息处理工作及计算机系统操作、维护与管理的员。3、职业等级:本职业共设三个等级,分别为初级(国家职业资格五级)、中级(国家…

java destroy_Java Process destroy()方法与示例

java destroy流程类destroy()方法 (Process Class destroy() method) destroy() method is available in java.lang package. destroy()方法在java.lang包中可用。 destroy() method is used to terminate the process abnormally. destroy()方法用于异常终止进程。 destroy() …