Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2268604
  • 博文数量: 293
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2170
  • 用 户 组: 普通用户
  • 注册时间: 2014-03-31 14:30
个人简介

自己慢慢积累。

文章分类

全部博文(293)

分类: Python/Ruby

2016-04-16 18:09:51

import time

print (time.strftime('%Y-%m-%d %H:%M:%S'))

上面这行其实就是下面这行的简写,因为strftime方法第二个参数默认就是time.localtime
print (time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()))

附上strftime的帮助

>>> 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.



阅读(693) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~