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

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

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

By 'column' I think you mean 'row'.

What's your system? Date math is tricky without GNU date.

Dear Corona688
sorry there was a error in the color, it is column, :slight_smile:
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?

But ... that column doesn't change.

And the row you highlighted before still changes.

What does 1170882025944002 represent, anyway?

something to start with to see the conversion ONLY:
awk -f jiam.awk myInputFile where jiam.awk is:

{
  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)
}

Mayhap sth. along this line:

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

That's the GPS date / time representation, starting at 6. Jan 1980, 0:00h UTC, in microseconds. Delta to *nix epoch is 315964800 sec.

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:

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:

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

Dear Xl and all

thanks a lot

---------- Post updated at 05:48 AM ---------- Previous update was at 12:38 AM ----------

Dear Xl

I have added

    return strftime(fmt, gps / 1E6 + 315964800 - 18)

To get exactly the time -3hs