ajieup 发表于 2021-5-8 09:54

python time方法疑惑

time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
time.strftime("%Y-%m-%d %H:%M:%S")
为什么这两个执行结果是一样的呢

kof21411 发表于 2021-5-8 09:59

因为time.strftime("%Y-%m-%d %H:%M:%S")默认调用参数就是time.localtime()

gentlespider 发表于 2021-5-8 10:52

看源码
def strftime(format, p_tuple=None): # real signature unknown; restored from __doc__
    """
    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.
   
这句话的意思是,当时间元组(也就是第二个参数)不存在,则使用localtime()返回的当前时间。
页: [1]
查看完整版本: python time方法疑惑