Page 1 of 1
6 digit milli-second Date time value
Posted: Thu Jul 13, 2023 6:19 pm
by MegumiSawada
Hi All,
I'm trying to get the current date time (in ISO 8601 format).
#DateTime1.Value := #DATETIMEX.Now
will return value like 2023-07-13 04:47:40.747.
As you can see, milli-seconde will be 3 digit.
Is there anyway to get 6 digit milli-second value like 2023-07-13 04:47:40.747123?
I tried everything I can think of, but I still get only 3 digit...
Best Regards,
Megumi Sawada
Re: 6 digit milli-second Date time value
Posted: Thu Jul 13, 2023 8:12 pm
by René Houba
Hi Megumi,
I don't know if that is possible in VL.
I did some testing with the FractionalSeconds part in debug, but see that it always returns max 3 values:
Define Field(#FractionalSeconds) Type(*DEC) Length(30) Decimals(15)
#FractionalSeconds := #DATETIMEX.Now.FractionalSeconds

- FractionalSeconds.PNG (4.46 KiB) Viewed 9914 times
Kind regards,
René
Re: 6 digit milli-second Date time value
Posted: Thu Jul 13, 2023 10:54 pm
by Dino
One alternative will be to use a widget to access a javascript function that can give you "microseconds". What you are looking is not milliseconds with 6 digit precision, but microseconds.
a good discussion is here... :
https://stackoverflow.com/questions/623 ... javascript
https://developer.mozilla.org/en-US/doc ... rmance/now
from a quick test with html/js, this lines can return the 6 digits microseconds you want:
Code: Select all
currentTime = performance.timeOrigin + performance.now();
alert(currentTime)
and using this page
https://dencode.com/en/date/iso8601
I can see that the time returned can be converted to iso8601 succesfully.... but....
iso8601 format only have 3 digits for millisecond, not microseconds.... so in that conversion you will loss the microseconds:
https://www.iso.org/iso-8601-date-and-time-format.html
then, you can create a widget like this, that can return the number in microseconds (I called it ROMicrosecond):

- microsecond.jpg (147.79 KiB) Viewed 9901 times
use this code for the implementation tab:
Code: Select all
function( PROTOTYPE, WIDGET )
{
PROTOTYPE.onCreateInstance = function() { }
// GetMicroseconds - Get Date and Time with microseconds from performance.now()
// Type: Decimal
PROTOTYPE.getGetMicroseconds = function() { return performance.timeOrigin + performance.now(); }
PROTOTYPE.setGetMicroseconds = function( decValue ) { this.m_GetMicroseconds = decValue; }
// Even though GetMicroseconds is read-only, setGetMicroseconds is still required for the default value
return WIDGET.Completed;
}
and for example test this widget in a web page:
Code: Select all
Begin_Com Role(*EXTENDS #PRIM_WEB) Theme(#SYS_THEME<MaterialDesignBlue>)
Define_Com Class(#ROMicrosecond) Name(#ROMicrosecond)
Evtroutine Handling(#Com_owner.Initialize)
#sys_web.Alert Caption(#ROMicrosecond.GetMicroseconds.AsString)
Endroutine
End_Com
Re: 6 digit milli-second Date time value
Posted: Fri Jul 14, 2023 6:21 pm
by MegumiSawada
Hi René and Dino,
Thank you for your reply. These helps me a lot!
Best Regards,
Megumi Sawada