Python time 获取经过格式化的时间点

举报
千江有水千江月 发表于 2021/07/14 22:42:16 2021/07/14
【摘要】 环境信息ModelArtsNotebook - pytorch1.4-cuda10.1-cudnn7-ubuntu18.04JupyterLab - Notebook - Conda-python3  time 获取经过格式化的时间点import timetime_now = time.time()# floattime_now,type(time_now)(1626273514.1452...

环境信息

  • ModelArts
    • Notebook - pytorch1.4-cuda10.1-cudnn7-ubuntu18.04
      • JupyterLab - Notebook - Conda-python3

time 获取经过格式化的时间点

import time
time_now = time.time()
# float
time_now,type(time_now)

(1626273514.14527, float)
local_time=time.localtime(time_now)
# 时间元组
local_time,type(local_time)

(time.struct_time(tm_year=2021, tm_mon=7, tm_mday=14, tm_hour=22, tm_min=38, tm_sec=34, tm_wday=2, tm_yday=195, tm_isdst=0),
 time.struct_time)
show1 = time.asctime(local_time)
show1,type(show1)

('Wed Jul 14 22:38:34 2021', str)
"""
年 %Y
月 %m
日 %d
时 %H
分 %M
秒 %S
"""
show2 = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time_now))
show2,type(show2)

('2021-07-14 22:38:34', str)

help

help(time.time)

Help on built-in function time in module time:

time(...)
    time() -> floating point number
    
    Return the current time in seconds since the Epoch.
    Fractions of a second may be present if the system clock provides them.

help(time.localtime)

Help on built-in function localtime in module time:

localtime(...)
    localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,
                              tm_sec,tm_wday,tm_yday,tm_isdst)
    
    Convert seconds since the Epoch to a time tuple expressing local time.
    When 'seconds' is not passed in, convert the current time instead.
help(time.asctime)

Help on built-in function asctime in module time:

asctime(...)
    asctime([tuple]) -> string
    
    Convert a time tuple to a string, e.g. 'Sat Jun 06 16:26:11 1998'.
    When the time tuple is not present, current time as returned by localtime()
    is used.
help(time.strftime)

Help on built-in function strftime in module time:

strftime(...)
    strftime(format[, tuple]) -> string
    
    Convert a time tuple to a string according to a format specification.
    See the library reference manual for formatting codes. When the time tuple
    is not present, current time as returned by localtime() is used.
    
    Commonly used format codes:
    
    %Y  Year with century as a decimal number.
    %m  Month as a decimal number [01,12].
    %d  Day of the month as a decimal number [01,31].
    %H  Hour (24-hour clock) as a decimal number [00,23].
    %M  Minute as a decimal number [00,59].
    %S  Second as a decimal number [00,61].
    %z  Time zone offset from UTC.
    %a  Locale's abbreviated weekday name.
    %A  Locale's full weekday name.
    %b  Locale's abbreviated month name.
    %B  Locale's full month name.
    %c  Locale's appropriate date and time representation.
    %I  Hour (12-hour clock) as a decimal number [01,12].
    %p  Locale's equivalent of either AM or PM.
    
    Other codes may be available on your platform.  See documentation for
    the C library strftime function.

相关链接


备注

  1. 欢迎各位同学一起来交流学习心得^_^
  2. 在线课程、沙箱实验、认证、论坛和直播,其中包含了许多优质的内容,推荐了解与学习。
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。