TCL 取时间、格式化时间

clock seconds 取一个整型值

用命令可以格式化时间

 

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 

取出日期中的值,作为变量使用。在需要的时候可以发挥作用

你可能感兴趣的:(TCL)