<div dir="ltr"><div>if I do this:</div><div>? cstr(date.fromutc(date(2019,10,27,2,30)))</div><div><br></div><div>Is it guaranteed that in all possible localizations I will always get this?:</div><div>10/27/2019 02:30:00</div><div><br></div><div>Because I need to write my own routines for Year(), Month(), etc...</div><div><br></div><div><br></div><div>Jussi<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Oct 27, 2019 at 8:26 PM Benoît Minisini <<a href="mailto:g4mba5@gmail.com">g4mba5@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Le 27/10/2019 à 18:22, T Lee Davidson a écrit :<br>
> On 10/26/19 9:42 PM, Jussi Lahtinen wrote:<br>
>> Is there a reliable way to detect any of those shenanigans happening <br>
>> to system clock?<br>
>> And how much is shifted and in what direction?<br>
>><br>
> <br>
>> Let's say I want this; date(2019,10,27,2,3) in UTC, but I'm in <br>
>> different time zone (or perhaps even suddenly changing time zone <br>
>> without any warning). How I get the Date() function to return correct <br>
>> values?<br>
>><br>
>> It would be easy, if date would accept one more argument; <br>
>> date(2019,10,27,2,3, "UTC")...<br>
>><br>
> <br>
> I think I must be missing something in what you are asking since I'm <br>
> almost certain that you, knowing more about Gambas than I, must already <br>
> be aware of the gb.util Date functions and System.TimeZone.<br>
> <br>
> It is recommended that a system with only Linux on it should have the <br>
> hardware (CMOS) clock set to UTC. If that is the case, then the system <br>
> clock should not change. (Linux uses the glibc time functions to convert <br>
> the system time to local time as needed using the time zone info stored <br>
> under, eg., /usr/share/zoneinfo.)<br>
> <br>
> System.TimeZone yields, "the number of seconds you must add to the local <br>
> time to get the UTC time." Since this number can be negative, this gives <br>
> us the amount of shift and the direction. Following the example in the <br>
> Wiki, if one's time zone is UTC+2, System.TimeZone will return -7200 <br>
> since one would actually have to subtract 7200 seconds to get back to a <br>
> UTC representation.<br>
> <br>
> gb.util has Date.FromUTC ("Move a date back to local time if its local <br>
> representation is actually in UTC.") and Date.ToUTC ("Move a date so <br>
> that its local representation is its UTC value."). So then perhaps one <br>
> could do:<br>
> Date.ToUTC(date(2019,10,27,2,3))<br>
> <br>
> <br>
> ___<br>
> Lee<br>
> <br>
<br>
That's it.<br>
<br>
You must understand that there is always an implicit timezone when <br>
dealing with a date as as string, or with the Date() function and the <br>
functions of the same family: Year(), Month()...<br>
<br>
The implicit timezone is always the local timezone (as returned by <br>
System.TimeZone) except for CStr() and CDate(), that assumes UTC timezone.<br>
<br>
Internally, the date is stored in UTC.<br>
<br>
Regards,<br>
<br>
-- <br>
Benoît Minisini<br>
<br>
----[ Gambas mailing-list is hosted by <a href="https://www.hostsharing.net" rel="noreferrer" target="_blank">https://www.hostsharing.net</a> ]----<br>
</blockquote></div>