My server time is in EDT. And i am sending automated mails from that server in which i need to display the current date time as per IST \(GMT\+5:30\). Please advice how to display the date time as per IST.
IST time leads 9:30 mins to EDT. and i wrote something like below.
What about using the TZ variable. Not sure it would help with that daylight saving problem; you may need to schedule a cron job to adapt TZ every 6 months.
Since India does not waste time with daylight saving time shifts, just setting TZ=IST-5:30 will give you the correct time in India at any time of year. For example, a few seconds ago:
TZ=GMT0 date;TZ=IST-5:30 date
produced the output:
Sat Mar 16 11:10:49 GMT 2013
Sat Mar 16 16:40:49 IST 2013
wow..!! , i did not know that shell has the ability to treat first one as variable assignment and next one it expands into a command. Thats a new thing i learnt today. Thank you
Both are variable assignments, but since they are at the beginning of a command (not complete commands on their own), the settings only affect affect the environment of the command being run. They do not affect the current shell execution environment. For example:
$ TZ=PST8PDT
$ date;TZ=IST-5:30 date;date
Sat Mar 16 07:13:53 PDT 2013
Sat Mar 16 19:43:53 IST 2013
Sat Mar 16 07:13:53 PDT 2013
$ echo $TZ
PST8PDT
$