[Gambas-user] Syntax of dates represented in a string

Benoit Minisini benoit.minisini at gambas-basic.org
Thu Nov 17 02:13:59 CET 2022


Hi,

To fix the difficulties encountered by Claus and others, I added in the 
last commit the ability to explicitly specify the timezone in a date 
inside a string.

For example (in english format):

"11/17/2022 01:41 UTC+1"

It should help those that don't get the difference between functions 
that use UTC implicitly, and functions that use local timezone implicitly.

With that, in French localization (UTC+1), you will have:

Print CDate("11/17/2022 01:41")
17/11/2022 02:41

Print Val("17/11/2022 01:41")
17/11/2022 01:41

Print CDate("11/17/2022 01:41 UTC")
17/11/2022 02:41

Print Val("17/11/2022 01:41 UTC")
17/11/2022 02:41

Print CDate("11/17/2022 01:41 UTC+1")
17/11/2022 01:41

Print Val("17/11/2022 01:41 UTC+1")
17/11/2022 01:41

To understand the printed result, remember that 'Print' internally uses 
'Str()', that converts the date to a string using the current 
localization and the local timezone.

Note that you can use "GMT" instead of "UTC", and there is still no 
function to format a date at a specific timezone other than the local one.

The other problem raised by Bruce (BB <adamnt42 at gmail.com>) is another 
beast: in a few words, how to know which timezone must be used at a 
specific date.

The data exists, but apparently the C library does not have any API for 
that.

Moreover, the problem can be circular: to define the specific date, you 
may need the timezone you are looking for.

So I don't think there is a solution for that at the moment.

Regards,

-- 
Benoît Minisini.


More information about the User mailing list