Python程序可显示当前时,分,秒和微秒
在下面的示例中-我们正在实现一个python程序来打印当前时,分,秒和微秒。
步骤:
从datetime模块导入datetime类
通过调用创建对象now()日期时间类的功能
使用以下对象提取并打印当前时,分,秒和微秒datetime.now()。
#使用Python程序打印当前时间,
#分钟,秒和微秒
#从导入日期时间类
#日期时间模块
from datetime import datetime
#创建对象
obj_now = datetime.now()#打印当前日期和时间
print("Current date & time: ", obj_now)
#提取并打印当前
#时,分,秒和微秒
print("Current hour =", obj_now.hour)
print("Current minute =", obj_now.minute)
print("Current second =", obj_now.second)
print("Current microsecond =", obj_now.microsecond)输出结果
Current date & time: 2020-03-09 08:52:48.262154 Current hour = 8 Current minute = 52 Current second = 48 Current microsecond = 262154
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西