[Gambas-user] Different quantities of seconds from UNIX date...
Benoît Minisini
g4mba5 at gmail.com
Sun Apr 8 00:51:20 CEST 2018
Le 08/04/2018 à 00:04, Jussi Lahtinen a écrit :
> It's not simple. How do I save and load consistently time & date as
> string given by user?
>
> If I use CDate and CStr, the problem occurs when the user gives time &
> date before the "daylight saving" applies, because it will be hour off
> when loaded after the "daylight saving" applies. IF the user is not in
> UTC time zone. This is because UTC+1 <--> UTC yields different result
> than UTC+2 <--> UTC.
>
> If I use Val and Str, the problem occurs when language is changed.
>
>
> Jussi
If you have a string that you know it is a date/time in local timezone
(daylight saving is automatically added by the system to the local
timezone, i.e. daylight saving "changes" the timezone), then you must
use Val() to convert it to a Date type.
And if you have to display a date to the user in its local timezone, you
have to use Str() or Print or Format().
If you use CDate(), then the string is assumed to be a date/time in UTC.
And if you use CStr(), the date is displayed in UTC, using the american
date format.
You have to deal with timezone "by hand" only if you want to manipulate
a string that represents a date that is not in UTC, and not in local
timezone, daylight time saving included.
If date strings were forced to always include the timezone, it would be
clearer. But this is not the case, the timezone is implicit, and it's
the kind of function you use that assumes it.
Regards,
--
Benoît Minisini
More information about the User
mailing list