Local time to GMT time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Local time to GMT time
# 1  
Old 02-14-2017
Local time to GMT time

Gents,

Please can help with this.

the column in red is the local time
the column in blue is the GPStime

Code:
4153152529951 2/12/17	12:00:04.980	951	2960	41531.0	52529.0	1170882022980002
4108153261942 2/12/17	12:00:07.944	942	2959	41081.0	53261.0	1170882025944002
41511523611660 2/12/17	1:55:32.180	1660	2959	41511.0	52361.0	1170888950180002
410675237398 2/12/17	7:36:48.980	98	2958	41067.0	52373.0	1170909426980002

I would like to get the time -3hrs in GMT time.

Example

Code:
4153152529951 2/11/17	21:00:04.980	951	2960	41531.0	52529.0	1170882022980002
4108153261942 2/11/17	21:00:07.944	942	2959	41081.0	53261.0	1170882025944002
41511523611660 2/11/17	22:55:32.180	1660	2959	41511.0	52361.0	1170888950180002
410675237398 2/12/17	04:36:48.980	98	2958	41067.0	52373.0	1170909426980002


Please advise. Thanks for your help

Last edited by jiam912; 02-14-2017 at 01:16 PM..
# 2  
Old 02-14-2017
By 'column' I think you mean 'row'.

What's your system? Date math is tricky without GNU date.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 02-14-2017
Dear Corona688
sorry there was a error in the color, it is column, Smilie
i am using debian 7. i try to do it manually (hr-3) but i belive it can be done automatically, maybe using the GPStime?
# 4  
Old 02-14-2017
But ... that column doesn't change.

And the row you highlighted before still changes.

What does 1170882025944002 represent, anyway?
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 02-14-2017
something to start with to see the conversion ONLY:
awk -f jiam.awk myInputFile where jiam.awk is:
Code:
{
  d=$2
  t=$3
  split(d,dA,"/")
  split(t,tA,"[:.]")

  dateSpec=sprintf("20%02d %02d %02d %02d %02d %02d", dA[3], dA[1], dA[3], tA[1], tA[2], tA[3])

  time=mktime(dateSpec)

  utc=strftime("%m/%d/%Y %H:%M:%S." tA[4], time, 1)

  printf("dateSpec->[%s] utc->[%s]\n", dateSpec, utc)
}


Last edited by vgersh99; 02-14-2017 at 02:22 PM..
This User Gave Thanks to vgersh99 For This Post:
# 6  
Old 02-14-2017
Mayhap sth. along this line:
Code:
awk -vGPS0=$(TZ=UTC date -d'1/6/1980 0:00' +%s) '{print "@" int($NF/1E6)+GPS0}' CONVFMT="%.f" file | LC_ALL=C TZ=+3 date -f-
Sat Feb 11 21:00:23  2017
Sat Feb 11 21:00:26  2017
Sat Feb 11 22:55:50  2017
Sun Feb 12 04:37:07  2017

Quote:
Originally Posted by Corona688
.
.
.
What does 1170882025944002 represent, anyway?
That's the GPS date / time representation, starting at 6. Jan 1980, 0:00h UTC, in microseconds. Delta to *nix epoch is 315964800 sec.

Last edited by RudiC; 02-14-2017 at 03:21 PM..
This User Gave Thanks to RudiC For This Post:
# 7  
Old 02-14-2017
jiam912, you seem to work with gpstime in your data files a fair bit. perhaps you would benefit from this GNU awk function strfgps() which operates like the strftime() function except with gpstime:

Code:
TZ=0 gawk '
function strfgps(fmt, gps) {
    gsub(/%f/, sprintf("%03d", gps % 1E6 / 1E3), fmt)
    return strftime(fmt, gps / 1E6 + 315964800)
}
{
  $2 = strfgps("%m/%d/%y", $NF)
  $3 = strfgps("%H:%M:%S.%f", $NF)
  print
}' OFS="\t" infile

I used gsub() to add support for the %f format => milliseconds as 3 digit number.


output:
Code:
4153152529951   02/11/17        21:00:22.980    951     2960    41531.0 52529.0 1170882022980002
4108153261942   02/11/17        21:00:25.944    942     2959    41081.0 53261.0 1170882025944002
41511523611660  02/11/17        22:55:50.180    1660    2959    41511.0 52361.0 1170888950180002
410675237398    02/12/17        04:37:06.980    98      2958    41067.0 52373.0 1170909426980002


Last edited by Chubler_XL; 02-14-2017 at 05:19 PM..
These 3 Users Gave Thanks to Chubler_XL For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

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: RAW_TME=042720171530 logmm=`echo $RAW_TME | cut -c1-2` logdd=`echo $RAW_TME |... (4 Replies)
Discussion started by: mrn6430
4 Replies

2. Shell Programming and Scripting

GMT to local Time conversion

How can I convert the following date format: New Log Date = 2016-12-30 23:50:33 GMT from GMT time to local time? Thanks (13 Replies)
Discussion started by: mrn6430
13 Replies

3. Post Here to Contact Site Administrators and Moderators

Server Upgrade Scheduled for Today - 7:30 GMT (2:30 PM Eastern Time)

Dear All, Today, somewhere around 7:30 GMT (2:30 PM Eastern Time) www.unix.com will go down for what we hope is around 15 - 20 minutes as we change out some hardware on the server. Thank you for your patience and support. Neo (0 Replies)
Discussion started by: Neo
0 Replies

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

5. Solaris

Enabling time service in local zones

Hi, Is it possible to enable the time service in local zones? E.g. erahmanz1% svcs -a | grep -i time STATE STIME FMRI disabled Sep_10 svc:/network/daytime:dgram disabled Sep_10 svc:/network/daytime:stream disabled Sep_10 svc:/network/time:dgram... (2 Replies)
Discussion started by: ERahman
2 Replies

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

7. HP-UX

change time mode from BST to GMT

I want to know how to change the time zone from BST to GMT avoid the daylight savings in hp-ux (3 Replies)
Discussion started by: tomjones
3 Replies

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

9. Shell Programming and Scripting

Time using Time::Local

Can someone tell me how to get the current date and time in the follwoing format, using Time::Local? MM/DD/YYYY HH:MI:SS AM/PM (1 Reply)
Discussion started by: ssmiths001
1 Replies
Login or Register to Ask a Question