Quote:
Originally Posted by khandu
I think the date command is universal for unix right?
|
They don't all have the same features, but a basic
date command should be available in all Unix and POSIX systems, including Linux, BSDs, and Mac OS X, yes.
Quote:
Originally Posted by khandu
I basically want to display different timezone time on command line. Is this correct?? Just as an example? Will it mess with my system time??
|
No, it will not mess with your system time. Use
Code:
env TZ=IST-5:30 date +'India: %I:%M %p %a'
to make sure you actually set the TZ environment variable for the date command (and the one command only), though. (I do not think the IST/UTC-5:30 format works, use
TZ=IST-5:30 or
TZ=UTC-05:30 or
TZ=:Asia/Calcutta instead.)
If you want to make sure the month and date names are in a specific language, you can use
Code:
env TZ=IST-5:30 LANG=en_US LC_ALL=en_US date +'India: %I:%M %p %a'
There is a specific locale called C or POSIX locale,
LANG=C LC_ALL=C, which is available on all systems, and pretty much matches the en_US locale.
POSIX systems, especially Linux and BSD (and Mac, as it is a BSD derivative I believe), are designed to work with multiple simultaneous users. The system time is in UTC, and is only adjusted when displayed to the user. The
/etc/timezone file is usually a symlink to the default timezone on the machine, and all the utilities read it to determine how the local time is derived from UTC. The TZ environment variable can be set, independently for each process, to override that. Remember: it does not change any system values at all, it just controls how the system values are interpreted and displayed by these utilities.
There is no danger of messing up your system time, when fooling around with these time utilities as a normal user. It's not like these systems are as braindead as Windows is. Even if you happen to set your TZ variable to a funny value, all you do is see the wrong local time in the utilities that see the wrong TZ value. Reset it -- it is empty by default on most systems -- and its fixed. Or close that shell, and start a new one; that'll also work.