localtime Tcl Command
NAME
localtime - Obtain the current time and/or date
SYNOPSIS
::dmh::localtime ?format?
DESCRIPTION
This command is used to obtain the current system time. Unless UTC (Universal Coordinated Time) is indicated, the result is for the local timezone. UTC time was formerly known as GMT (Greenwich Mean Time). The environmental variable TZ should be set to establish or override the local timezone, and the use of Daylight Saving Time. This variable is usually configured by the system administrator when the operating system is installed.
The value of the argument format controls the output format of the result. If no format code is given or if the code is out of range, the default format is used. The following format codes are supported. These format choices are also available for the mktime command.
- default
- YYYY MM DD HH MM SS DayOfWeek DayOfYear With this format, single digit numbers are padded with a space so that the first 6 fields are always at the same offsets in the string. DayOfWeek ranges 0 to 6 with 0 being Sunday. DayofYear ranges from 0 to 365 with 0 being January 1. In general, single digit numbers are padded with leading zeroes on all of the other formats. The leading 0's may need to be removed if the text is used in integer expressions since the usual Tcl input routines use leading zeroes to indicate octal values.
- 0
- The C language asctime() result string for the local time; for example Sun May 28 19:03:43 1995. This result format does not depend on the current locale (configured Country and language).
- 1
- Same as the above except but the value is for UTC.
- 2
- The POSIX count of seconds since 1970 eg., 801705320
- 3
- HHMMSS
- 4
- HH:MM:SS
- 5
- YYYYMMDD
- 6
- YYYY MM DD
- 7
- MM DD YY
- 8
- DD-Mon-YYYY HH:MM:SS
- 9
- YYYY-MM-DD HH:MM:SS in the local timezone. Formats 9, 10, 15 and 16 are especially useful for sorting when ordinary string comparison is used.
- 10
- YYYY-MM-DD HH:MM:SS for UTC
- 11
- UTC_seconds microseconds
This format is available if your system supports the gettimeofday() C function.
The localtime command guarantees that a unique, monotonically increasing result is returned
everytime format 11, format 15, or format 16 is obtained, but this result usually does not have the
full millisecond accuracy. For example, on Win32 platforms, the microseconds argument is only
accurate to the nearest millisecond. The mktime command can be used to convert this
format into any of the other formats.
- 12
- date and time formatted for the current locale using the strftime() function, format "%c".
- 13
- date formatted for the current locale using the strftime() function, format "%x".
- 14
- time formatted for the current locale using the strftime() function, format "%X".
- 15
- YYYY-MM-DD HH:MM:SS.uuuuuu in the local timezone.
If you use this value for a database key, you may have problems with Daylight Saving Time
in the fall, when the clock is shifted back an hour.
As with format 11, this format is available only on platforms that support gettimeofday().
- 16
- YYYY-MM-DD HH:MM:SS.uuuuuu for UTC. This value is free of problems
with Daylight Saving Time changes.
As with format 11, this format is available only on platforms that support gettimeofday().
- 17
- YYYY-MM-DD HH:MM:SS.mmm in the local timezone.
This format is available only on platforms that support gettimeofday().
- 18
- YYYY-MM-DD HH:MM:SS.mmm for UTC. This value is free of problems
with Daylight Saving Time changes.
This format is available only on platforms that support gettimeofday().
- reset
- This command argument causes the discarding of cached system time values that are used to return
unique values for the 11, 15, and 16 format choices. The subcommand needs to be called if the computer
system clock is updated to an earlier time while the application is running.
AUTHOR
Ed Hume, Hume Integration Software
SEE ALSO
mktime
dmh_ntp_install
KEYWORDS
time, calender, date, mktime