
用命令可以格式化时间
clock format 时间变量 -format 参数
参数可以为:
%% Insert a %.
%a Abbreviated weekday name (Mon, Tue, etc.).
%A Full weekday name (Monday, Tuesday, etc.).
%b Abbreviated month name (Jan, Feb, etc.).
%B Full month name.
%c Locale specific date and time.
%d Day of month (01 - 31).
%H Hour in 24-hour format (00 - 23).
%I Hour in 12-hour format (00 - 12).
%j Day of year (001 - 366).
%m Month number (01 - 12).
%M Minute (00 - 59).
%p AM/PM indicator.
%S Seconds (00 - 59).
%U Week of year (01 - 52), Sunday is the first day of the week.
%w Weekday number (Sunday = 0).
%W Week of year (01 - 52), Monday is the first day of the week.
%x Locale specific date format.
%X Locale specific time format.
%y Year without century (00 - 99).
%Y Year with century (e.g. 1990)
%D Date as %m/%d/%y.
%e Day of month (1 - 31), no leading zeros.
%h Abbreviated month name.
%n Insert a newline.
%r Time as %I:%M:%S %p.
%R Time as %H:%M.
%t Insert a tab.
%T Time as %H:%M:%S.
举例
when CLIENT_ACCEPTED {
set curtime [clock seconds]
log local0.warning "当前时间$curtime"
set formattime [clock format $curtime -format {%D %T}]
log local0.warning "格式时间$formattime"
}
curtime表现如下:
| 15:31 | 192.168.162.254 | warnings | tmm tmm[1045]: Rule test_length: 当前时间1206689510 |
%D %T表现如下
| 15:31 | 192.168.162.254 | warnings | tmm tmm[1045]: Rule test_length: 格式时间03/28/08 15:31:50 |
when CLIENT_ACCEPTED {
set curtime [clock seconds]
log local0.warning "当前时间$curtime"
set formattime [clock format $curtime -format %m]
set lin [expr $formattime+1]
log local0.warning "格式时间$formattime ..$lin"
}
上面这个输入如下
| 15:37 | 192.168.162.254 | warnings | tmm tmm[1045]: Rule test_length: 格式时间03 ..4 |
取出日期中的值,作为变量使用。在需要的时候可以发挥作用
这是张旭(Hardy Chung)的个人网站,世界Web数据库中关于我的最全面的资料。你可以通过Google或者Baidu之类的搜索引擎方便的找到我。我在这个网站上同时发布我的网络日志。
我现在就职于一家软件公司从事电信行业的数据仓库,经营分析系统建设的相关工作。
我喜欢程序设计,对算法有浓厚的研究兴趣,熟悉C,C++。立志成为一名软件工程师,但我对目前的工作也十分满意。
我同时喜欢网页设计,独立设计过各种类型的网站和专题;对web2.0和网站营销有浅薄的认识。
我最近完成网站项目为“四季伊人瑜伽苏州会馆”的形象站。
我愿意把我所有的好东西在这里与大家分享,虽然时间和精力有限,但我会尽量这样去做。你可以通过下面的地址邮件地址与我联系:
chungxu/at/gmail.com
嫌邮件麻烦,可以直接在这里留言给我
04月 15th, 2008 at 1:39 am
晕哦~想看看你再忙什么.....结果是一大堆数据 汗~