Converting UTC time
Posted
#1
(In Topic #1233)
Trainee
Now I need to adjust this time according to my local timezone.
I know that I can read the UTC time from my system with the shell-command "timedatectl", but how do I adjust the time to my local time ?
Any help would be appreciated.
Posted
Guru

/lang/format - Gambas Documentation
Also see Date() command as you don't really want to be running shell timedatectl when gambas has built in date functions.
/lang/date - Gambas Documentation
There is lots of info in the gambas help system. / - Gambas Documentation
Posted
Trainee
The UTC-time read from file is in another timezone than my local time and I need to adjust the read time to my timezone before I can use it in my program.
Posted
Guru

Format will convert local time from UTC
And if you need to show the timezone there is t or tt
/cat/userformat - Gambas Documentation
Posted
Guru

to convert your "YYYY-MM-DD"T"HH:MM
gambas expects utc dates to be american format and time separated by a space.
so to make it gambas compliant Date object we need to remove the T and Z and jumble the date values around to be like
"mm/dd/yyyy hh:nn:ss"
Code (gambas)
- ' turn your time format into a date object
- ' convert date values to american format by reversing and swapping month/day
- aYMD = aYMD.Reverse()
Not sure if that's exactly what you want but should help you towards getting to the correct data.
Posted
Guru

I'm reading info from a file and get date and time information on the form "YYYY-MM-DD"T"HH:MMS"Z (an example: 2024-04-27T09:25:00Z).
What does this date refer to? It looks like it's the file date. What time zones are involved?
Posted
Regular

Maybe this can help you:toyman61 said
But the Date()-function does not contain any information about which timezone I'm in and that is essential to me.
The UTC-time read from file is in another timezone than my local time and I need to adjust the read time to my timezone before I can use it in my program.
/comp/gb/system/timezone - Gambas Documentation
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Trainee
I just wanted to get the timezone offset so that I could adjust the hour parameter in the Date-function to reflect my local timezone.
Here is the code snippet that I finally ended up with:
Dim tDate As String = Format$(Now, "yyyy-mm-ddThh:nn:sstt")
Dim sDate As String[] = Split(tDate, "+")
Dim iOffset As Integer = Val(sDate[1]) / 100
Then I could use the iOffset parameter to add to the hour part of the time stamp read from file and then it is adjusted to my local timezone.
Thanks to all of you!
Posted
Guru

toyman61 said
Thanks for all replies!
I just wanted to get the timezone offset so that I could adjust the hour parameter in the Date-function to reflect my local timezone.
Here is the code snippet that I finally ended up with:
Dim tDate As String = Format$(Now, "yyyy-mm-ddThh:nn:sstt")
Dim sDate As String[] = Split(tDate, "+")
Dim iOffset As Integer = Val(sDate[1]) / 100
Then I could use the iOffset parameter to add to the hour part of the time stamp read from file and then it is adjusted to my local timezone.
Thanks to all of you!
Aah I see
How about just this one liner?
Only using the tt with Format it only gets the time offset so don't need to Split()
and Val() changes the string +0100 to just integer 100
Posted
Trainee
I'm using your one-liner in my program.
1 guest and 0 members have just viewed this.


