12.5.5.1     clock options

This Time command provides additional formatting options to display time in various formats.  The option argument determines what action is carried out by the command to format the time string it returns. The legal options (which may be abbreviated) are:

clock clicks

Return a high-resolution time value as a system-dependent integer value based on CPU cycle counter. This value should only be used for the relative measurement of elapsed time.

 

clock format

clock format clockValue ?-format string? ?-gmt boolean?

Converts an integer time value, typically returned by clock seconds, clock scan, or the atime, mtime, or ctime options of the file command, to human-readable form. If the -format argument is present the next argument is a string that describes how the date and time are to be formatted.

Format string descriptors consist of a % followed by a format descriptor character. All other characters are copied into the result.

Format descriptors

Valid Format descriptors are:

%%    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)

%Z      Time zone name.

 

If the -format argument is not specified, the format string used is:
"%a %b %d %H:%M:%S %Z %
Y"

If the -gmt argument is present the next argument must be a boolean which if true will format time as Greenwich Mean Time. If false then the local time zone will be used as defined by the Windows operating environment.

 

# example  - clock format reformats the time. Here it is converted back to  HH:MM:SS format

set time2 [clock seconds]

SETVAL "minutes1=[clock format $time2 -format %H:%M:%S]"

clock scan

clock scan dateString ?-base clockVal? ?-gmt boolean?

Convert dateString to an integer clock value (see clock seconds). This command will convert any standard date and time string including standard time zone abbreviations. If only a time is specified, the current date is assumed. If the string does not contain a time zone mnemonic, the local time zone is assumed. The -gmt argument overrides this setting to Greenwich Mean Time.

If the -base flag is specified, the next argument must contain an integer clock value. Only the date in this value is used, not the time. This is useful for determining the time on a specific day.

Date String

The dateString consists of zero or more specifications of the following form:

time              Time of day, which is of the form: hh?:mm?:ss?? ?meridian? ?zone? or hhmm ?meridian?

?zone?          If no meridian is specified, hh is interpreted on a 24-hour clock.

date              Month and day with optional year. The acceptable formats are mm/dd?/yy?, monthname dd ?, yy?, dd monthname ?yy? and day, dd monthname yy. The default year is the current year. If the year is less than 100, we treat the years 00-68 as 2000-2068 and the years 69-99 as 1969-1999.

relative time A specification relative to the current time.

Acceptable units are year, month, week, day, hour, minute (or min), and second (or sec). The units can be specified as a singular or plural, as in 3 weeks. These modifiers may also be specified: tomorrow, yesterday, today, now, last, this, next, ago.

# example3 - clock scan converts a time to seconds

# for example if %TMTIME = 16:57:45 on Sep 13 2004

# clockscantime = 1095119865  

# note that if no date is specified todays date is assumed

# the clockscan will wrap around days and months

set time1 [GETVAL %TTMTIME]

SETVAL "clockscantime=[clock scan $time1]"

 

 

clock seconds

Returns the current date and time as an integer value of seconds. The value is usually defined as total elapsed time from an ‘‘epoch’’ used by the Windows Operating System. You shouldn’t assume the value of the epoch will be the same or synchronized on all clients or nodes. For example on September 14, 2004 at 11:04:15 am clock seconds returns a value of 1095185055. In the example below, time2 = 1095185055 on Sept. 14, 2004.

# example  - clock seconds shows current time in seconds

# if screen scrip,t this is local time of client

SETVAL "seconds1=[clock seconds]"

set time2 [clock seconds]