Operating System - HP-UX
1833994 Members
5378 Online
110063 Solutions
New Discussion

Convert system time to any other Time zone time

 
Sanjeev gupta_2
Frequent Advisor

Convert system time to any other Time zone time

Hi

Is there any way in hp-ux to Convert system time to any other Time zone time.
say local time to IST,GMT,etc.

THX
sanjeevg
6 REPLIES 6
Sridhar Bhaskarla
Honored Contributor

Re: Convert system time to any other Time zone time

Hi Sanjeev,

Time zone setting is only for the interpretation of the time. HP-UX maintains it's time always in GMT.

YOu can change the timezone setting by modifying /etc/TIMEZONE file and then login again. However, if changing of TIMEZONE affects your application, you will need to bring it down prior to changing the time. All the 'login' sessions and their child processes will have to be closed. I have seen some primitive applications merely depending on the date and time without counting timezone. For ex., a script that uses a simple 'date' command to get the hour and minute information for calculations may produce wrong results if you change the timezone. So, it is a good idea to reboot the system (or atleast restart your apps) if you are planning to change the timezone.

'set_parms timezone' is HP's supported command to change the timezone.

-Sri

You may be disappointed if you fail, but you are doomed if you don't try
Sundar_7
Honored Contributor

Re: Convert system time to any other Time zone time

I think you got to be little clear :-).

You need to set the TZ variable to the approriate time zone.

Are you looking to set the time zone permanently or for use in any other scripts/programs ?
Learn What to do ,How to do and more importantly When to do ?
Sanjeev gupta_2
Frequent Advisor

Re: Convert system time to any other Time zone time

HI ALL


Actually the case is this that i have a file in which i have records of different servers( located at different time zone) in front of that record i have local system time, now i want to convert this local time to that specific time zone time. is there any way to convert it as i am not allowed to do ssh like thing to pick date from that server.
pl. guide.

Bill Hassell
Honored Contributor

Re: Convert system time to any other Time zone time

As mentioned, TZ will translate the current HP-UX time (which is always GMT) into any timezone. /etc/TIMEZONE sets TZ for each user as they login but it can be changed at anytime. For users logging in from another country, just add TZ= and all the system time, file timestamps, etc will be correct for the remote timezone. Now since your file already has ASCII text with the timestamp, conversion can only be done with an extensive script so it can handle prev/next day conversions.

The only practical way to fix this is at the remote site. When you create the file, change the TZ value to your central server's TZ value and then get the date, like this:

MYDATE=$(TZ=EST5EDT;date)
or
MYDATE=$(TZ=PST8PDT;date)

Now the remote machine can store the central server's timestamp locally.


Bill Hassell, sysadmin
Sanjeev gupta_2
Frequent Advisor

Re: Convert system time to any other Time zone time

Hi
can i convert my sytem time to seconds and again convert seconds to system time

thx
sanjeev gupta
A. Clay Stephenson
Acclaimed Contributor

Re: Convert system time to any other Time zone time

For that Perl is about as easy as it gets:

Epoch seconds:

perl -e 'print time'
1097266110
To convert epoch seconds back to a formatted time:

TZ=EST5EDT perl -e 'print scalar localtime(1097266110)'
Fri Oct 8 16:08:30 2004

Man perlfunc and note gmtime, localtime, time for more details.
If it ain't broke, I can fix that.