[Gambas-user] Format function changes date value
Benoît Minisini
g4mba5 at gmail.com
Thu Jun 7 22:43:13 CEST 2018
Le 07/06/2018 à 21:36, Jussi Lahtinen a écrit :
> This is how I do it, when I want to save & load the values as string,
> without being influenced by timezones.
>
> Write as string:
>
> sStringToBeSaved = Subst("&1/&2/&3 &4:&5:&6",
> Format(Month(hDateAndTimel), "0#"), Format(Day(hDateAndTimel), "0#"),
> Year(hDateAndTimel), Format(Hour(hDateAndTimel), "0#"),
> Format(Minute(hDateAndTime), "0#"), Format(Second(hDateAndTimel), "0#"))
>
>
> Read as date:
>
> Dim sStr, sDate, sTime As String[]
>
> sStr = Split(sLoadedString, " ")
>
> sDate = Split(sStr[0], "/")
> sTime = Split(sStr[1], ":")
>
> hDateAndTime = Date(sDate[2], sDate[0], sDate[1], sTime[0],
> sTime[1], sTime[2])
>
>
>
> Jussi
>
This is wrong: you are using Year(), Month(), Day()... functions that
assume a local date. It works only if the date is read in the same
timezone as the write.
You have to, and just have to use CStr() and CDate(). I.e. write dates
in UTC, and read them back in UTC.
Regards,
--
Benoît Minisini
More information about the User
mailing list