LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-19-2007, 01:42 AM   #1
lothario
Member
 
Registered: Apr 2004
Posts: 340

Rep: Reputation: 30
date command with different time zones


I have a shell script which starts with the date command.
This tells us when the shell script was run.
At the moment it says:
Tue Dec 18 23:33:46 PST 2007

This was all good, so far.

But now I have to run the same script and show the time several
time zones at the same time. So the output should look like this:
Tue Dec 18 23:33:46 PST 2007
....................CST 2007
....................MST 2007
....................EST 2007
and so on

Without changing the time zone on the system, how can I display the time:
In several time zones.
OR
Issue the date command repeatedly with a different time zone.

Last edited by lothario; 12-19-2007 at 01:55 AM.
 
Old 12-19-2007, 01:59 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Code:
for i in EST CST MST; do TZ=$i date "+%c %Z" -d "now"; done


Cheers,
Tink
 
Old 12-19-2007, 04:37 PM   #3
lothario
Member
 
Registered: Apr 2004
Posts: 340

Original Poster
Rep: Reputation: 30
Thank you.
 
Old 12-19-2007, 04:42 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Welcome; if the machine is kind of slow-ish, or you're worried that time-
stamps may wrap around while the loop runs, you could get the result of
one date, and use that for the input of the one run in the loop.

Something like:
Code:
result=`date`;for i in EST CST MST; do TZ=$i date "+%c" -d "$result"; done


Cheers,
Tink
 
Old 12-19-2007, 04:47 PM   #5
lothario
Member
 
Registered: Apr 2004
Posts: 340

Original Poster
Rep: Reputation: 30
Aah haa. Got it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Put a date/time from the command line Jzarecta Linux - Software 1 10-03-2007 12:48 PM
Setting system date and time affecting the clock and date on BIOS satimis Ubuntu 7 09-21-2007 08:02 AM
date command counts time quicker than hwclock (RTC) carl0ski Linux - Software 2 12-29-2005 05:32 AM
Start Date + Time Duration = End Date/Time calculator? ToBe Linux - General 3 09-26-2005 10:17 AM
date command do not keep time set shanenin Linux - Software 1 09-04-2004 08:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration