在很多时候,日期格式化的问题都会存在的,现在作一个总结,并不断更新:
目前本文中包含的有:
unix/linux下shell中的日期格式化
JSP网页中的日期格式化(包括取系统当前日期和当前日期前后N天的日期) unix/linux下shell中的日期格式化问题:
例子(test.sh): #!/bin/sh
echo "现在时间:`date '+%Y%m%d %T'`"
输出:现在时间:20070629 08:53:22
解析:date返回当前时间,'+%Y%m%d %T'控制时间格式,每个参数都有特定的意义,下面是各种参数
%% a literal %
%a locale's abbreviated weekday name (Sun..Sat)
%A locale's full weekday name, variable length (Sunday..Saturday)
%b locale's abbreviated month name (Jan..Dec)
%B locale's full month name, variable length (January..December)
%c locale's date and time (Sat Nov 04 12:02:33 EST 1989)
%C century (year divided by 100 and truncated to an integer) [00-99]
%d day of month (01..31)
%D date (mm/dd/yy)
%e day of month, blank padded ( 1..31)
%F same as %Y-%m-%d
%g the 2-digit year corresponding to the %V week number
%G the 4-digit year corresponding to the %V week number
%h same as %b
%H hour (00..23)
%I