# Dates, timestamps and timezones

**URL:** <https://forum.xojo.com/t/dates-timestamps-and-timezones/42743>\
**Category:** General\
**Created:** [March 31, 2018, 5:21pm UTC](https://forum.xojo.com/t/dates-timestamps-and-timezones/42743 "2018-03-31T17:21:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![GarryPettet](https://forum.xojo.com/user_avatar/forum.xojo.com/garrypettet/32/31_2.png) [@GarryPettet](https://forum.xojo.com/u/GarryPettet)\
**Post date:** [March 31, 2018, 5:21pm UTC](https://forum.xojo.com/t/dates-timestamps-and-timezones/42743/1 "2018-03-31T17:21:52Z")

</div>

Hi guys,

I’m trying to get the current date/time in Paris. I’m using an HTTP API that returns the following JSON for the date `2018-03-31 19:10:55`:

```auto
{"status":"OK","message":"","countryCode":"FR","countryName":"France","zoneName":"Europe\\/Paris","abbreviation":"CEST","gmtOffset":7200,"dst":"1","dstStart":1521939600,"dstEnd":1540688400,"nextAbbreviation":"CET","timestamp":1522523455,"formatted":"2018-03-31 19:10:55"}
```

I can’t seem to get the correct time and date (2018-03-31 19:10:55) using the `Xojo.Core.Date` class and I’m sure it’s because I’m using the constructor incorrectly.

Using the `timestamp` value from the JSON yields `2018-03-31 21:10:55`

`dim tz as new Xojo.Core.TimeZone("Europe/Paris")
dim d as new Xojo.Core.Date(1522523455, tz)`

Using `dstStart` yields `2018-03-25 03:00:00`

`dim tz as new Xojo.Core.TimeZone("Europe/Paris")
dim d as new Xojo.Core.Date(1521939600, tz)`

Using `dstEnd` yields `2018-10-28 02:00:00`

`dim tz as new Xojo.Core.TimeZone("Europe/Paris")
dim d as new Xojo.Core.Date(1540688400, tz)`

The best I can get is two hours out. What am I doing wrong here? Can anyone help?

Thanks,

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [March 31, 2018, 5:36pm UTC](https://forum.xojo.com/t/dates-timestamps-and-timezones/42743/2 "2018-03-31T17:36:56Z")

</div>

On a machine set to US EST time zone, I get the exact France time with this :

[code]Dim d As Xojo.Core.Date = Xojo.Core.Date.Now

dim tz as new Xojo.Core.TimeZone(“Europe/Paris”)

Dim myDate As Xojo.Core.Date = Xojo.Core.Date.Now ’ Get date for current time zone

Dim FRDate As New Xojo.Core.Date(myDate.SecondsFrom1970, tz)

msgbox FRDate.ToText[/code]

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [March 31, 2018, 5:38pm UTC](https://forum.xojo.com/t/dates-timestamps-and-timezones/42743/3 "2018-03-31T17:38:11Z")

</div>

use gmtoffset which is 7200 seconds, that is the 2 hours you need to substract to the timestamp field.

---

<div class="post-metadata">

**Author:** ![GarryPettet](https://forum.xojo.com/user_avatar/forum.xojo.com/garrypettet/32/31_2.png) [@GarryPettet](https://forum.xojo.com/u/GarryPettet)\
**Post date:** [March 31, 2018, 6:10pm UTC](https://forum.xojo.com/t/dates-timestamps-and-timezones/42743/4 "2018-03-31T18:10:25Z")

</div>

> [@380394:@Jean-Yves Pochez](#):
>
> use gmtoffset which is 7200 seconds, that is the 2 hours you need to substract to the timestamp field.

Thanks!

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [March 31, 2018, 6:59pm UTC](https://forum.xojo.com/t/dates-timestamps-and-timezones/42743/5 "2018-03-31T18:59:22Z")

</div>

Hum…

I would rather use “Europe/Paris” instead of a 2 hours offset, since it takes care of daylight saving time.

Otherwise the offset changes with daylight saving time or not. That is less robust.

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [March 31, 2018, 7:25pm UTC](https://forum.xojo.com/t/dates-timestamps-and-timezones/42743/6 "2018-03-31T19:25:46Z")

</div>

I hope gmtoffset should change to 3600 when not in daylight saving time ?

---

<div class="post-metadata">

**Author:** ![James\_Dooley](https://forum.xojo.com/user_avatar/forum.xojo.com/james_dooley/32/164_2.png) [@James\_Dooley](https://forum.xojo.com/u/James_Dooley)\
**Post date:** [April 1, 2018, 1:23am UTC](https://forum.xojo.com/t/dates-timestamps-and-timezones/42743/7 "2018-04-01T01:23:42Z")

</div>

> [@380394:@Jean-Yves Pochez](#):
>
> use gmtoffset which is 7200 seconds, that is the 2 hours you need to substract to the timestamp field.

While this might fix it mathematically, it does not explain why the api reports Paris local time plus two additional hours. The offset indicates that Paris local time in summer time is GMT + 2, looks like a bug to me.

---

<div class="post-metadata">

**Author:** ![GarryPettet](https://forum.xojo.com/user_avatar/forum.xojo.com/garrypettet/32/31_2.png) [@GarryPettet](https://forum.xojo.com/u/GarryPettet)\
**Post date:** [April 1, 2018, 6:31am UTC](https://forum.xojo.com/t/dates-timestamps-and-timezones/42743/8 "2018-04-01T06:31:46Z")

</div>

Do you think the bug is with Xojo or the API?

I’ve settled on this approach which seems to work:

`dim t as Text = "2018-03-31 19:10:55" ' Pulled from the "formatted" JSON key
try
  dim d as Xojo.Core.Date = Xojo.Core.Date.FromText( t )
catch
  ' Fail
end try`

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [April 1, 2018, 8:49am UTC](https://forum.xojo.com/t/dates-timestamps-and-timezones/42743/9 "2018-04-01T08:49:35Z")

</div>

I verified that the time was right with Xojo.Core.Date. I am inclined to believe the web API is off.

---

<div class="post-metadata">

**Author:** ![James\_Dooley](https://forum.xojo.com/user_avatar/forum.xojo.com/james_dooley/32/164_2.png) [@James\_Dooley](https://forum.xojo.com/u/James_Dooley)\
**Post date:** [April 2, 2018, 2:21am UTC](https://forum.xojo.com/t/dates-timestamps-and-timezones/42743/10 "2018-04-02T02:21:14Z")

</div>

[quote=380468:@Garry Pettet]Do you think the bug is with Xojo or the API?

I’ve settled on this approach which seems to work:

`dim t as Text = "2018-03-31 19:10:55" ' Pulled from the "formatted" JSON key
try
  dim d as Xojo.Core.Date = Xojo.Core.Date.FromText( t )
catch
  ' Fail
end try`[/quote]

The API by the look of it.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 7:09pm UTC](https://forum.xojo.com/t/dates-timestamps-and-timezones/42743/11 "2020-10-29T19:09:22Z")

</div>


