# Local time to GMT time

**URL:** <https://community.unix.com/t/local-time-to-gmt-time/365050>\
**Category:** Shell Programming and Scripting\
**Created:** [February 14, 2017, 11:57am UTC](https://community.unix.com/t/local-time-to-gmt-time/365050 "2017-02-14T11:57:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiam912](https://community.unix.com/user_avatar/community.unix.com/jiam912/32/2027_2.png) [@jiam912](https://community.unix.com/u/jiam912)\
**Post date:** [February 14, 2017, 11:57am UTC](https://community.unix.com/t/local-time-to-gmt-time/365050/1 "2017-02-14T11:57:10Z")

</div>

Gents,

Please can help with this.

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

```nohighlight
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

```nohighlight
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

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [February 14, 2017, 12:10pm UTC](https://community.unix.com/t/local-time-to-gmt-time/365050/2 "2017-02-14T12:10:17Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![jiam912](https://community.unix.com/user_avatar/community.unix.com/jiam912/32/2027_2.png) [@jiam912](https://community.unix.com/u/jiam912)\
**Post date:** [February 14, 2017, 12:13pm UTC](https://community.unix.com/t/local-time-to-gmt-time/365050/3 "2017-02-14T12:13:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [February 14, 2017, 1:12pm UTC](https://community.unix.com/t/local-time-to-gmt-time/365050/4 "2017-02-14T13:12:54Z")

</div>

But ... that column doesn't change.

And the row you highlighted before still changes.

What does 1170882025944002 represent, anyway?

---

<div class="post-metadata">

**Author:** ![vgersh99](https://community.unix.com/user_avatar/community.unix.com/vgersh99/32/14851_2.png) [@vgersh99](https://community.unix.com/u/vgersh99)\
**Post date:** [February 14, 2017, 1:13pm UTC](https://community.unix.com/t/local-time-to-gmt-time/365050/5 "2017-02-14T13:13:39Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [February 14, 2017, 2:07pm UTC](https://community.unix.com/t/local-time-to-gmt-time/365050/6 "2017-02-14T14:07:23Z")

</div>

Mayhap sth. along this line:

```plaintext
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

```

> [@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.

---

<div class="post-metadata">

**Author:** ![Chubler\_XL](https://community.unix.com/user_avatar/community.unix.com/chubler_xl/32/2077_2.png) [@Chubler\_XL](https://community.unix.com/u/Chubler_XL)\
**Post date:** [February 14, 2017, 3:31pm UTC](https://community.unix.com/t/local-time-to-gmt-time/365050/7 "2017-02-14T15:31:31Z")

</div>

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:

```nohighlight
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:

```nohighlight
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

```

---

<div class="post-metadata">

**Author:** ![jiam912](https://community.unix.com/user_avatar/community.unix.com/jiam912/32/2027_2.png) [@jiam912](https://community.unix.com/u/jiam912)\
**Post date:** [February 15, 2017, 5:48am UTC](https://community.unix.com/t/local-time-to-gmt-time/365050/8 "2017-02-15T05:48:08Z")

</div>

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

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

```

To get exactly the time -3hs
