Convert GMT date and time to CST


 
Thread Tools Search this Thread
Operating Systems Solaris Convert GMT date and time to CST
# 1  
Old 04-27-2017
Convert GMT date and time to CST

I need away to convert the following GMT date and time value RAW_TME= 042720171530 "mmddccyyhhmm" to Localhost time. In this case it is in central time.
Here is what I came up with but it does not look efficient:
Code:
RAW_TME=042720171530
 logmm=`echo $RAW_TME | cut -c1-2`
logdd=`echo $RAW_TME  | cut -c3-4`
logyy=`echo $RAW_TME  | cut -c5-8`
logth=`echo $RAW_TME  | cut -c9-10`
logtm=`echo $RAW_TME  | cut -c11-12`
GLOG_TME="$logyy-$logmm-$logdd $logth:$logtm:00 GMT"
t=$(mktemp)
O_DDD_T=`TZ=Z touch -t $(echo "$GLOG_TME" | sed -e 's/ GMT$//' -e 's/[ :-]//g' -e 's/\(..\)$/.\1/') $t
(
  set -- $(ls -E $t)
  rm $t
  echo $6 $7 | sed 's/..........$//'
)`
echo $O_DDD_T

Output is :

Code:
2017-04-27 10:30:00 CST

Is there a leaner easier way to do this ?

Last edited by mrn6430; 04-27-2017 at 02:36 AM..
# 2  
Old 04-27-2017
With a recent version of ksh (on a system that doesn't have a GNU date utility) in a terminal session where the default timezone is the US Pacific timezone, the following:
Code:
Date_GMT=042720170740
TZ=CST6CDT printf '%(%m%d%Y%H%M)T\n' "${Date_GMT:0:8} ${Date_GMT:8:2}:${Date_GMT:10} GMT"

produces the output:
Code:
042720170240

So, with a GNU date utility on a Linux system using a recent bash, the following might work:
Code:
Date_GMT=042720170740
TZ=CST6CDT date -d "${Date_GMT:0:8} ${Date_GMT:8:2}:${Date_GMT:10} GMT" '%m%d%Y%H%M'

If the timezone being used in your terminal session is already set to use US Central time zone, you can drop the TZ=CST6CDT at the start of the date command line.

PS: Note that a timestamp of 0740 GMT will NOT convert to a timestamp of 10:30:00 CST; with the given date, it would either convert to 2017-04-27 01:40:00 CST or, if you aren't in the parts of Indiana that don't observe daylight saving time, 2017-04-27 02:40:00 CDT. Getting this date format would need the date format string:
Code:
'%Y-%m-%d %H:%M:%S %Z'

instead of:
Code:
'%m%d%Y%H%M'


Last edited by Don Cragun; 04-27-2017 at 02:51 AM.. Reason: Fix date utility format string and add PS.
# 3  
Old 04-27-2017
Getting this error:
Code:
Date: illegal option -- d
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]

# 4  
Old 04-27-2017
You filed this question in the Linux forum. What operating system (including the distribution and version number) are you using?
# 5  
Old 04-27-2017
My bad. it is solaris 10 that I am using.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Timestamp in text to Serial Date-Time

Hi, I have a data file where the timestamp is in the style of: 2016-10-11 07:01:23.375-500 which is yyyy-mm-dd hh-mm-ss-000 then time conversion from UTC What i need to do is convert these timestamps from the above format to a the Serial Date format (i.e 42,654.2920446 ) now.. if... (14 Replies)
Discussion started by: AshBax
14 Replies

2. Shell Programming and Scripting

Convert Second Column Date Into EPOCH Time And Print Complete Row

Hello Team, I am stuck in getting the required output in the following case. Please help. My input file is aa|08/01/2016 bb|08/15/2016 I wish to convert the file into aa|epoch time bb|epoch time I am using following code: (3 Replies)
Discussion started by: angshuman
3 Replies

3. Shell Programming and Scripting

Convert epoch time to Julian date

Need assistance in converting an epoch time to Julian date To get epoch perl -e 'use Time::Local; print timelocal(1,5,2,12,10,2008), "\n"' (3 Replies)
Discussion started by: ajayram_arya
3 Replies

4. Shell Programming and Scripting

Using awk or nawk to convert epoch time to date format

Looking for some help and usually when I do a search this site comes up. Hopefully someone can give me a little direction as to how to use one of these two commands to achieve what I'm trying to do. What am I trying to do? I need to take the time value in epoch format returned from the... (5 Replies)
Discussion started by: minigts
5 Replies

5. Shell Programming and Scripting

how to convert date time to epoch time in solaris

Hi, Is there any easy way to convert date time(stored in shell variable ) to epoch time in solaris box? As +%s is working on linux but not on solaris, also -d option is not working. Any suggestion please? (6 Replies)
Discussion started by: anshuman0507
6 Replies

6. 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

7. Shell Programming and Scripting

Convert date to unix time

Hi, I need to convert a date in the format yyyy-mm-dd to unix seconds, shell script or perl would be ok since there is no hour/second, we can assume 12am every day thanks in advance funksen (4 Replies)
Discussion started by: funksen
4 Replies

8. Shell Programming and Scripting

Convert Epoch Time to Standard Date and Time & Vice Versa

Hi guys, I know that this topic has been discuss numerous times, and I have search the net and this forum for it. However, non able to address the problem I faced so far. I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Discussion started by: DrivesMeCrazy
5 Replies

9. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

I have a file named "suspected" with series of line like these : {'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''} {'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies

10. Shell Programming and Scripting

Script to convert GMT to Asia/Hong Kong time

hi friends, this is my first time with this type of script so please pardon my ignorance. i have this script in which a piece of code needs to be added which can have the Asia/Hong kong time as well. system date and format is GMT so no problem with GMT and even EST is covered..i have ato add new... (5 Replies)
Discussion started by: xejatt
5 Replies
Login or Register to Ask a Question