Chinaunix首页 | 论坛 | 博客
  • 博客访问: 64492
  • 博文数量: 14
  • 博客积分: 328
  • 博客等级: 一等列兵
  • 技术积分: 160
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-22 12:19
文章分类

全部博文(14)

文章存档

2012年(14)

分类: Python/Ruby

2012-11-14 20:05:46

下载TimeDate模块包:TimeDate

在脚本中,加载模块包:


点击(此处)折叠或打开

  1. use Date::Parse;
  2. use Date::Format;

设定一个标题,按一定的格式打印某天的日期:


点击(此处)折叠或打开

  1. my $yesterday = time2str("%Y%m%d", time - 3600 * 24);

其格式标准参见CPAN文档:

摘录如下:


点击(此处)折叠或打开

  1. %% PERCENT
  2.         %a day of the week abbr
  3.         %A day of the week
  4.         %b month abbr
  5.         %B month
  6.         %c MM/DD/YY HH:MM:SS
  7.         %C ctime format: Sat Nov 19 21:05:57 1994
  8.         %d numeric day of the month, with leading zeros (eg 01..31)
  9.         %e like %d, but a leading zero is replaced by a space (eg 1..32)
  10.         %D MM/DD/YY
  11.         %G GPS week number (weeks since January 6, 1980)
  12.         %h month abbr
  13.         %H hour, 24 hour clock, leading 0's)
  14.         %I hour, 12 hour clock, leading 0's)
  15.         %j day of the year
  16.         %k hour
  17.         %l hour, 12 hour clock
  18.         %L month number, starting with 1
  19.         %m month number, starting with 01
  20.         %M minute, leading 0's
  21.         %n NEWLINE
  22.         %o ornate day of month -- "1st", "2nd", "25th", etc.
  23.         %p AM or PM
  24.         %P am or pm (Yes %p and %P are backwards :)
  25.         %q Quarter number, starting with 1
  26.         %r time format: 09:05:57 PM
  27.         %R time format: 21:05
  28.         %s seconds since the Epoch, UCT
  29.         %S seconds, leading 0's
  30.         %t TAB
  31.         %T time format: 21:05:57
  32.         %U week number, Sunday as first day of week
  33.         %w day of the week, numerically, Sunday == 0
  34.         %W week number, Monday as first day of week
  35.         %x date format: 11/19/94
  36.         %X time format: 21:05:57
  37.         %y year (2 digits)
  38.         %Y year (4 digits)
  39.         %Z timezone in ascii. eg: PST
  40.         %z timezone in format -/+0000

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