[Gambas-user] Date(Now) with time component under Ubuntu?

Rolf-Werner Eilert rwe-sse at osnanet.de
Tue Dec 4 13:16:13 CET 2018


Am 04.12.18 um 12:56 schrieb Benoît Minisini:
> Le 04/12/2018 à 11:23, Rolf-Werner Eilert a écrit :
>> To give you an idea of the problem, here is a code snippet from this 
>> second application, it is in Form_Open:
>>
>> -----
>>    t$ = Date(Now)
>>    heute = String.Mid(t$, 4, 2) & "-" & String.Left(t$, 2) & "-" & 
>> String.Mid(t$, 7, 4)
>>    DerTag.Tag = Date(Now)
>>    DerTag.Text = "heute, " & Wochentag(Date(Now)) & ", " & 
>> Replace(heute, "-", ".")
>> -----
>>
>>
>>
>> Today (4th December)
>> - t$ becomes "12.03.2018 23:00:00"
>> - 'heute' of course becomes "12-03-2018"
>>
>> Now it's curious:
>> - DerTag.Tag becomes "04.12.2018 00:00:00" i. e. day and hour +1 !!
>>
>> And of course, it goes wrong here:
>> - DerTag.Text becomes "heute, Dienstag, 03.12.2018"
>>
>>
>> How to solve this mess???
>>
>> Regards
>> Rolf
>>
>>
> 
> Read carefully the documentation about Date(), avoid implicit conversion 
> from Date to String, Read carefully the documentation about Print, 
> CStr() and Str(), and just don't mix local and universal date 
> representations.
> 
> For example, let's analyze the following expression:
> 
> t$ = Date(Now) ' Assuming that t$ is a String variable
> 
> Now -> Return a Date value corrresponding to the current date & time.
> 
> Date(Now) -> Return the date part, in the current localization (i.e. the 
> current timezone). It means that the time part is set to 00:00:00, but 
> in the current timezone.
> 
> t$ = Date(Now) -> Assign the previous date value to a string variable, 
> hence applying first the automatic conversion from Date to String. So it 
> actually means...
> 
> t$ = CStr(Date(Now))
> 
> CStr() converts the date into a UTC date representation, not in your 
> local representation. So you won't see a pure date: the time is shifted 
> according to your timezone.
> 
> For the other expressions, I can't tell you, you don't give any 
> information about the functions and variable you use.
> 
> And I guess it worked before because you used a Gambas version where you 
> had a bug in date / string conversion. I can't say more without you 
> giving more details.
> 
> Regards,
> 

This explains it  perfectly: I used an older Gambas version and 
programmed based on a buggy date-string conversion. Guess this is 
exactly what happened.

And now I understood how these conversions are really meant to function.

Thank you for that explanation!

Rolf


More information about the User mailing list