Hello everybody. My first topic. Here we go:
I'm a beginner in this, yet I used to do programming for a while in VB, C, and C++.
I wrote a macro in OO Basic that deals with TIME. Since our time is changing with DST, I'd like to put the present GMT time in a separate cell.
Since I cannot see the contents (types, descriptions, variables, etc) of the system calls (is there a way?), I am struggling. I searched the whole forum & internet, in vein.
So, my question is:
Is there a way to get GMT in real time, with OO Basic calls?
Thank you all in advance,
AL
[Solved] How can I get GMT (UTC) time into my macro (Basic)?
[Solved] How can I get GMT (UTC) time into my macro (Basic)?
Last edited by MrProgrammer on Fri Aug 02, 2019 6:11 pm, edited 2 times in total.
Reason: Moved from Calc forum to OpenOffice Basic, Python, BeanShell, JavaScript
Reason: Moved from Calc forum to OpenOffice Basic, Python, BeanShell, JavaScript
OpenOffice 4.1.6 on Windows 10 64-Bit
Re: How can I get GMT (UTC) time into my macro (OO Basic)?
If I know it exactly, the AOO and the LO can get the time and date from the PC operating system. If the time/date of the operating system is set to GMT, then the NOW() function will get GMT in the Calc cell and in the StarBasic too.
I do not know, if it is possible to get the type of the datetime from the PC (from operating system)
Similar topics:
viewtopic.php?f=9&t=49417
https://ask.libreoffice.org/en/question ... -timezone/
I do not know, if it is possible to get the type of the datetime from the PC (from operating system)
Similar topics:
viewtopic.php?f=9&t=49417
https://ask.libreoffice.org/en/question ... -timezone/
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: How can I get GMT (UTC) time into my macro (OO Basic)?
I do not know how to do this in Basic. The python function below writes the current UTC into A1 of Sheet1. If you do not want to translate your entire macro to python, you could call a python routine from Basic that returns the UTC as a string. I am not on a computer where I can test that. A forum search on getScriptProvider should find some examples.
Code: Select all
from datetime import datetime
def getUTC():
doc = XSCRIPTCONTEXT.getDocument()
sheets = doc.Sheets
sheet1 = sheets.getByName('Sheet1')
oCell = sheet1.getCellRangeByName("A1")
UTC = datetime.utcnow()
oCell.String = UTC.isoformat()
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: How can I get GMT (UTC) time into my macro (OO Basic)?
Code: Select all
Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
[Solved] How can I get GMT (UTC) time into my macro (OO Basi
Thank you everybody, especially Villeroy. You gave me enough inspiration to find my way.
Here is what I came up with (and it works). I hope it helps the next person who'd needs this. Please feel free to perfect it further.
Keep good work rolling,
AL
Here is what I came up with (and it works). I hope it helps the next person who'd needs this. Please feel free to perfect it further.
Code: Select all
Option Explicit
Private Declare Sub GetSystemTime Lib "Kernel32" (ByRef lpSystemTime As SYSTEMTIME)
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Sub GetUTCtime
Dim UTCnow As SYSTEMTIME
Call GetSystemTime(UTCnow)
MsgBox(UTCnow.wHour & ":" & UTCnow.wMinute & " Z", 0, "GMT/UTC/Zulu Time")
End Sub
AL
OpenOffice 4.1.6 on Windows 10 64-Bit
Re: [Solved] How can I get GMT (UTC) time into my macro (Bas
Thank you for sharing your solution.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice