[Gambas-user] [Gambas Bug Tracker] Bug #704: Format does not handle time separator correctly

Benoît Minisini gambas at ...1...
Sat Aug 29 11:55:05 CEST 2015


Le 29/08/2015 11:08, Charlie Reinl a écrit :
> Am Samstag, den 29.08.2015, 04:22 +0300 schrieb Jussi Lahtinen:
>>> correct me if I go wrong, I still don't see for what we need the
>>> localization.
>>> Having a Date or Date/Time and we want to format it, where we need
>>> localisation there for.
>>>
>>> Using german date is Format(now(),"dd.mm.yyyy") but I also can write
>>> Format(now(),"mm/dd/yyyy") or Format(now(),"dd-mm-yyyy") but also
>>> Format(now(),"dd;mm;yyyy") yes that should work (it's a ';' not a ':')
>>> Please enlighten me, I can't see the usage of localization in that
>>> converting.
>>>
>>
>> How I supposed to verify output of Format(now(),"mm/dd/yyyy") ?
>> Correct result can be 08.29.2015 or 08/29/2015 depending on the
>> localization (or even something completely different).
>>
>>
>> Jussi
>
> Salut Jussi,
>
> attached you a quick hack who shows that the Format don't
> use the localization.
>

For the last time, Format$() *does* use the localization settings, as 
explicitly stated in the documentation.

But it uses them for its special formatting characters only. Non-special 
characters are just inserted as is in the resulting string.

If you want to write translatable date/time code, you have to use 
pre-defined date formats (gb.GeneralDate and ).

If none of the pre-defined formats fit your needs, then you have to 
create your own by:

1) Determining the order of date and time components by analysing the 
formatting of a cleverly chosen date with gb.ShortDate and gb.ShortTime. 
See the source code of DateChooser control for the details.

2) Using the "/" and ":" formatting characters in the format string.

Regards,

-- 
Benoît Minisini




More information about the User mailing list