- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Display the current time in different timezones
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2002 02:22 PM
11-19-2002 02:22 PM
I need to display the current time in several timezones. Any ideas? I've tried to use the date command but sometimes the seconds don't match.
TIA, Neil
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2002 02:24 PM
11-19-2002 02:24 PM
Re: Display the current time in different timezones
You can set the TZ variable before the 'date' command and it will show the time in that time zone. Something like this:
# date
Tue Nov 19 17:28:18 EST 2002
# echo $TZ
EST5EDT
# TZ=CST6EDT date
Tue Nov 19 16:28:32 CST 2002
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2002 02:26 PM
11-19-2002 02:26 PM
Re: Display the current time in different timezones
TZ=CST6CDT date
but it worked all the same.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2002 02:28 PM
11-19-2002 02:28 PM
Re: Display the current time in different timezones
Time display is handled by the TZ environment variable.
For instance
export TZ=CST6CDT
will display the time for the US Central time zone.
Just adjust the TZ value for whatever zone you wish.
You don't need to change the actual system time.
Rgds,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2002 02:29 PM
11-19-2002 02:29 PM
Re: Display the current time in different timezones
Simply set the appropriate timezone for the duration of the command only; for examle:
TZ=PST8PDT date
Note that my normal TZ is EST5EDT so the above tells me the Pacific coast time.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2002 02:33 PM
11-19-2002 02:33 PM
SolutionTZ=EST5CDT date
TZ=CST6CDT date
as you indicated, if your dates commands don't execute during the same epoch second, you're bad.
Here's the way to do it:
NOW=$(perl -e 'print time()')
TIMEZONES="EST5EDT CST6CDT MST7MDT PST8PDT"
for T in ${TIMEZONES}
do
TZ=${T} perl -e "print scalar localtime(${NOW})"
# NOTE THE DOUBLEQUOTES; WE WANT THE SHELL TO EXPAND ${NOW}
echo
done
That should do it, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2002 02:42 PM
11-19-2002 02:42 PM
Re: Display the current time in different timezones
This too will work:
# date;TZ=PST8PDT date;TZ=MST7MDT date;TZ=CST6CDT date
...return(ed):
Tue Nov 19 17:42:03 EST 2002
Tue Nov 19 14:42:03 PST 2002
Tue Nov 19 15:42:03 MST 2002
Tue Nov 19 16:42:03 CST 2002
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2002 02:47 PM
11-19-2002 02:47 PM
Re: Display the current time in different timezones
I took your question to mean that you wanted to display the same time (to the second) in multiple timezones. If that is correct then you must somehow use a command that captures that time and then displays that same epoch seconds values in all the timezones. If my interpretation is correct, then the multiple date commands will worl perfectly almost all the time BUT if you truly want to display consistant times then you need the Perl solution or something equivalent.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2002 02:49 PM
11-19-2002 02:49 PM
Re: Display the current time in different timezones
I guess I wasn't very clear. I had already tried the TZ=MST7MDT
export TZ
date
approach but very rarely after doing all nine timezones, the first time displayed would not match the last time by one second. Clay seemed to understand my problem and I think I'll use his method after I understand what it does.
Thanks for all your quick help.
Neil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2002 02:52 PM
11-19-2002 02:52 PM
Re: Display the current time in different timezones
I absolutely agree.
Warmest regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2002 02:58 PM
11-19-2002 02:58 PM
Re: Display the current time in different timezones
I suppose the last part of Neil's original post jumped out at me. Of course, the problem with my method is that the time might be stale by one second ("The moving finger ..." - some of that Omar Khayam stuff) but at least the times will all zig or they will all zag.
Neil,
The only tricky part is the call to time to capture the epoch seconds. I intentionally did this as part Perl and part shell for those less familiar with Perl. If I were doing for me, it would be pure Perl.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2002 03:09 PM
11-19-2002 03:09 PM
Re: Display the current time in different timezones
Clay has the best solution [as usual :) ]. I got excited and typed in an answer and then read the whole question. Another spot where Perl really shines, since there is no easy way in the shell to grab a particular time and use it for several different 'date' commands.
I love these little types of scripts. Anything that will turn a $$$,$$$ dollar computer into a simple $30 clock. ;)
JP