Sponsored Content
Top Forums Shell Programming and Scripting Convert UTC time into current UNIX sever time zone Post 302879315 by Don Cragun on Wednesday 11th of December 2013 07:19:09 PM
Old 12-11-2013
Quote:
Originally Posted by blackrageous
This does seem to be a bit vague. Here is a useful tip and in this case I am using the korn shell. The idea here is to temporarily define the TZ environment variable; that is....
Code:
TZ=CDT date

would define the TZ var for the execution of the date command...regardless of what the default TZ setting is.

By example...
Code:
[josephgr@oc0887178221 ~]$ date; TZ=UTC date
Wed Dec 11 17:57:03 CST 2013
Wed Dec 11 23:57:03 UTC 2013

This isn't a ksh feature, it is standard behavior required for any shell conforming to the POSIX standards or the Single UNIX Specifications. But, the format shown above is not correct. A valid setting for TZ will include at least the zone's name and offset from UTC. The normal setting for Texas in the United States would be TZ=CST6CDT (not TZ=CDT) and TZ=UTC happens to work because the offset from UTC to UTC is 0, but the output from the commands:
Code:
TZ=CDT date
TZ=UTC date

will be identical except for the difference in the time zone name. Compare the results above with:
Code:
TZ=CST6CDT date

where you'll see a 6 hour difference in time (this time of year) as well as a difference in the time zone name. The output from the above three commands should be something like:
Code:
Thu Dec 12 00:17:50 UTC 2013
Thu Dec 12 00:17:50 UTC 2013
Wed Dec 11 18:17:50 CST 2013


Last edited by Don Cragun; 12-11-2013 at 08:20 PM.. Reason: Fix typo.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Unix Time to Standard Time

I have a list of interfaces and time the interface was last active. I can't figure out how to convert the time in the second column, Fa1/14 0 Se0/0/0 0 Fa1/11 0 Fa1/9 0 Fa1/0 0 Se0/0/1 1240401408 Gi1/0 0 Fa0/0 1240401408 Fa1/3 0 Fa1/8 0 Fa1/15 0 Fa1/13 0 Fa1/10 0 Fa1/1 0 Fa1/12... (7 Replies)
Discussion started by: mrlayance
7 Replies

2. Shell Programming and Scripting

Convert UTC time to Date

Hi, I need to convert a number representing time in UTC seconds to a date. Ex: 3BE0082C --> Oct 31 2001 15:31:08 I have tried the following perl command but it gives a different answer? $ perl -e 'print scalar localtime(shift), "\n"' 3BE00B2C Thu Jan 1 03:00:03 1970 Any ideas? Thanks. :) (10 Replies)
Discussion started by: GNMIKE
10 Replies

3. AIX

Convert UTC time to local time ?

Hello, Using AIX6.1 box. I have UTC time value and need to convert it to local time value - I mean time zone and DST should be taken into consideration. I hope it could be done using shell environment - I don't want to write a program. thanks Vilius ---------- Post updated at 02:30 PM... (2 Replies)
Discussion started by: vilius
2 Replies

4. Shell Programming and Scripting

Find and Convert UTC Time to PST Time

Hello All - I have a script that grabs data from the net and outputs the following data 46029 46.144 -124.510 2010 07 26 22 50 320 4.0 6.0 2.2 9 6.8 311 1012.1 -0.9 13.3 13.5 13.3 - - 46041 47.353 -124.731 2010 07 26 22 50 250 2.0 3.0 1.6 8 6.4 - 1011.6 - ... (0 Replies)
Discussion started by: drexnefex
0 Replies

5. AIX

Convert time (YYYYMMDD HHMMSS) to UTC

Okay, so let's say we have a string like: 20110105_193345 This represents: January 5th, 2011 = 20110105 24-hour style time 19:33:45 = 193345 Okay, so we have our time. It's January 5th, 2011 at 19:33:45. I want to convert this time from Eastern Time Zone (which it currently is in)... (1 Reply)
Discussion started by: syndex
1 Replies

6. UNIX for Dummies Questions & Answers

UTC time and Local time

Hi, A few days ago I changed my CentOS box's timezone to -07:00. Now the date commands output look like this (run almost simultaneously, less than 1 second delay).. # date Mon Sep 5 20:23:40 PDT 2011 # date -u Tue Sep 6 03:24:05 UTC 2011 The hours difference seems correct, but why is... (2 Replies)
Discussion started by: forte712
2 Replies

7. Solaris

modifying date and time and time zone on solaris 5.10 with (redundant server) veritas

I have a cluster of two Solaris server (veritas cluster). one working and the other is standby I am going to change the date on them , and am looking for a secure solution as it is giving an important service. my opinion is that the active one doesn't need to be restarted (if I don't change the... (1 Reply)
Discussion started by: barry1946
1 Replies

8. Shell Programming and Scripting

Displaying current date time of EDT in IST time

Hi Folks, 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. ... (6 Replies)
Discussion started by: Showdown
6 Replies

9. AIX

Change Time Zone to UTC without DST

Hello AIX friends, We have timezone settings on our AIX 6.1 boxes set to Europe/London. How can I change it to UTC timezone with Daylight saving disabled. After running "smit chtz_user" I don't see UTC option in the listing. Please advise. TIA (3 Replies)
Discussion started by: prvnrk
3 Replies

10. UNIX for Dummies Questions & Answers

How to change the time zone in UNIX??

hi, my system date and time zone is PDT. whenever i append date time stamp to a file it appends the system date thats PDT date time zone. i want to append GMT time zone. is there a mechanism or option which can append the date time stamp according to GMT. (4 Replies)
Discussion started by: Little
4 Replies
ctime(3C)																 ctime(3C)

NAME
ctime(), ctime_r(), asctime(), asctime_r(), daylight(), difftime(), gmtime(), gmtime_r(), localtime(), localtime_r(), mktime(), timezone(), tzname(), tzset() - convert date and time to string SYNOPSIS
DESCRIPTION
Convert the broken-down time contained in the structure pointed to by timeptr and return a pointer to a 26-character string in the form: All the fields have constant width. returns NULL and sets errno to if tm_year in is less than 0 or is greater than 8099. In both 32-bit and 64-bit HP-UX, the minimum date supported by is January 1 00:00:00 1900 and the maximum date supported by is December 31 23:59:59 9999. is identical to except that it places the result in the user supplied and returns a pointer to upon success. A buffer length of at least 26 is required. Convert the calendar time pointed to by timer, representing the time in seconds since the Epoch, and return a pointer to the local time in the form of a string. Equivalent to: The minimum date supported by in both 32-bit and 64-bit HP-UX is Friday December 13 20:45:52 UTC 1901. The maximum dates supported by are Tuesday January 19 03:14:07 UTC 2038 and Friday December 31 23:59:59 UTC 9999 in 32-bit HP-UX and 64-bit HP-UX, respectively. In 64-bit HP-UX, returns NULL and sets errno to if timer is less than the number of seconds that corresponds to the mini- mum date supported (i.e., as defined in or exceeds the number of seconds that corresponds to the maximum date supported. is identical to except that it places the result in the user supplied and returns a pointer to upon success. A buffer length of at least 26 is required. Return the difference in seconds between two calendar times: time1 - time0. Convert directly to Coordinated Universal Time (UTC), the time standard used by the HP-UX operating system. returns a pointer to the structure described below. The minimum date supported by in both 32-bit and 64-bit HP-UX is Friday December 13 20:45:52 UTC 1901. The maximum dates supported by are Tuesday January 19 03:14:07 UTC 2038 and Friday December 31 23:59:59 UTC 9999 in 32-bit HP-UX and 64-bit HP-UX, respectively. In 64-bit HP-UX, returns NULL and sets errno to if timer is less than the number of seconds that corresponds to the mini- mum date supported (i.e., as defined in or exceeds the number of seconds that corresponds to the maximum date supported. is identical to except that stores the result in the pointed to by and returns upon success. Correct for the time zone and any summer time zone adjustments (such as Daylight Savings Time in the USA), according to the contents of the environment variable (see below). returns a pointer to the structure described below. The minimum date supported by in both 32-bit and 64-bit HP-UX is Friday December 13 20:45:52 UTC 1901. The maximum dates supported by are Tuesday January 19 03:14:07 UTC 2038 and Friday December 31 23:59:59 UTC 9999 in 32-bit HP-UX and 64-bit HP-UX, respectively. In 64-bit HP-UX, returns NULL and sets errno to if timer is less than the number of seconds that corresponds to the mini- mum date supported (i.e., as defined in or exceeds the number of seconds that corresponds to the maximum date supported. is identical to except that stores the result in the pointed to by and returns upon success. Convert the broken-down time (expressed as local time) in the structure pointed to by timeptr into a calendar time value with the same encoding as that of the values returned by The original values of the and components of the structure are ignored, and the original values of the other compo- nents are not restricted to the ranges indicated below. A positive or zero value for causes to initially presume that Daylight Saving Time respectively is or is not in effect for the specified time. A negative value for causes to attempt to determine whether Daylight Saving Time is in effect for the specified time. Upon successful completion, all the components are set to represent the specified calendar time, but with their values forced to the ranges indicated below. The final value of is not set until and are determined. returns the specified calendar time encoded as a value of type The minimum date supported by in both 32-bit and 64-bit HP-UX is Friday December 13 20:45:52 UTC 1901. The maximum dates supported by are Tuesday January 19 03:14:07 UTC 2038 and Friday December 31 23:59:59 UTC 9999 in 32-bit HP-UX and 64-bit HP-UX, respectively. For 32-bit if the calendar time cannot be represented, the function returns the value and sets to Note the value also corresponds to the time 23:59:59 on Dec 31, 1969 (plus or minus time zone and Daylight Saving Time adjustments). Thus it is necessary to check both the return value and to reliably detect an error condition. The behavior of 64-bit beyond the supported ranges is undefined. Sets the values of the external variables timezone, daylight, and tzname according to the contents of the environment variable (independent of any time value). The functions and (see strftime(3C)) call and use the values returned in the external variables described below for their operations. can also be called directly by the user. When the environment variable is not set, checks the default file for the timezone value and sets timezone values based on that. The file contains the timezone value used by when the environment variable is not set. The format for the file is same as format without the prefix Please check environ(5) for format. If the value of the timezone cannot be determined using the environment variable or the file it is set to the default value of EST5EDT. If the timezone is set to the default value of EST5EDT and the timezone adjustment file is not avail- able, the timezone is set to a default value of UTC (Coordinated Universal Time). can be modified for an appropriate default value for timezone. The header file contains declarations of all relevant functions and externals. It also contains the structure, which includes the follow- ing members: int tm_sec; /* seconds after the minute - [0,61] */ int tm_min; /* minutes after the hour - [0,59] */ int tm_hour; /* hours - [0,23] */ int tm_mday; /* day of month - [1,31] */ int tm_mon; /* month of year - [0,11] */ int tm_year; /* years since 1900 */ int tm_wday; /* days since Sunday - [0,6] */ int tm_yday; /* days since January 1 - [0,365] */ int tm_isdst; /* daylight savings time flag */ The value of is positive if a summer time zone adjustment such as Daylight Savings Time is in effect, zero if not in effect, and negative if the information is not available. The external variable contains the difference, in seconds, between UTC and local standard time (for example, in the U.S. Eastern time zone (EST), is 5*60*60). The external variable is non-zero only if a summer time zone adjustment is specified in the environment variable. The external variable contains the local standard and local summer time zone abbreviations as specified by the environment variable. EXTERNAL INFLUENCES
Locale The category determines the interpretation of the bytes within format as single and/or multi-byte characters. Environment Variables The function uses the contents of to set the values of the external variables and also determines the time zone name substituted for the and directives and the time zone adjustments performed by and Two methods for specifying a time zone within are described in environ(5). International Code Set Support Single and multibyte character code sets are supported. RETURN VALUE
For and if the buffer is of insufficient length, a NULL is returned and errno set to and return a NULL and set errno to if NULL pointers are passed in as arguments. A NULL is returned and errno is set to if the input to the following routines is not within the supported range: APPLICATION USAGE
The return values for and point to static data whose contents is overwritten by each call. WARNINGS
Users of and should also note that these functions now conform to POSIX.1c. The old prototypes of these functions are supported for compat- ibility with existing DCE applications only. The range of extends to 61 to allow for the occasional one or two leap seconds. However, the "seconds since the Epoch" value returned by (see time(2)) and passed as the timer argument does not include accumulated leap seconds. The structure generated by and will never reflect any leap seconds. Upon successful completion, forces the value of the component to the range [0,59]. AUTHOR
was developed by AT&T and HP. SEE ALSO
time(2), getdate(3C), setlocale(3C), strftime(3C), tztab(4), environ(5), lang(5), langinfo(5), thread_safety(5). STANDARDS CONFORMANCE
ctime(3C)
All times are GMT -4. The time now is 03:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy