Chinaunix首页 | 论坛 | 博客
  • 博客访问: 454416
  • 博文数量: 481
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 1040
  • 用 户 组: 普通用户
  • 注册时间: 2013-01-06 14:09
文章分类

全部博文(481)

文章存档

2013年(483)

我的朋友

分类: Python/Ruby

2013-02-28 12:40:04

In [104]: time.strftime("%H:%M:%S",time.localtime())
Out[104]: '12:04:36'

In [105]: time.strftime("%Y-%m-%d",time.localtime())
Out[105]: '2011-06-07'

In [107]: time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
Out[107]: '2011-06-07 12:09:21'

In [121]: time.strftime("%Y-%m-%y %H:%M:%S",time.gmtime())
Out[121]: '2011-06-11 04:17:28'

localtime返回tuple格式的时间,有一个和它类似的函数叫gmtime(),2个函数的差别是时区,gmtime()返回的是0时区的值,localtime返回的是当前时区的值。

ISOFORMAT:
In [106]: datetime.date.today().isoformat()
Out[106]: '2011-06-07'


参考:
%aLocale’s abbreviated weekday name. 
%ALocale’s full weekday name. 
%bLocale’s abbreviated month name. 
%BLocale’s full month name. 
%cLocale’s appropriate date and time representation. 
%dDay of the month as a decimal number [01,31]. 
%HHour (24-hour clock) as a decimal number [00,23]. 
%IHour (12-hour clock) as a decimal number [01,12]. 
%jDay of the year as a decimal number [001,366]. 
%mMonth as a decimal number [01,12]. 
%MMinute as a decimal number [00,59]. 
%pLocale’s equivalent of either AM or PM.(1)
%SSecond as a decimal number [00,61].(2)
%UWeek number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0.(3)
%wWeekday as a decimal number [0(Sunday),6]. 
%WWeek number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0.(3)
%xLocale’s appropriate date representation. 
%XLocale’s appropriate time representation. 
%yYear without century as a decimal number [00,99]. 
%YYear with century as a decimal number. 
%ZTime zone name (no characters if no time zone exists). 
%%A literal '%' character.
阅读(268) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~