03-12-2021 03:34 AM
Hello,
Is there a way to get the current date and time in Zulu format?
Using c# the command is:
DateTime.Now.ToUniversalTime().ToString("u"));
This creates:
2021-03-12 06:39:37Z
Can this be done in teststand without an extra dll?
Thanks
03-18-2021 02:01 AM
Hi,
I think this discussion might be useful:
03-18-2021 04:29 AM
Hi,
thank you for the link.
But i am looking for a solution in only testtand with the tools that are available in teststand.
07-03-2025 10:50 AM - edited 07-03-2025 10:54 AM
This can be done. I was using System.DateTime in .NET for several years until just now, when I figured out how to do this natively.
I'm sure @OnlyOne already knows this as someone familiar with C#, but to the uninitiated, let's get an explanation of UNIX time out of the way:
UNIX time is defined as "Seconds since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC)"
This is sometimes referred to as "seconds since 1970," or UNIX time because, well, UNIX systems use this type of timestamp. (Linux, too)
"It's a UNIX system. I know this."
UNIX time's epoch is in UTC, and we can take advantage of this by using some math to figure out which hour of the day it is in Zulu/UTC/GMT time.
Here's some code that will do what you're asking:
// Get current UNIX time
Locals.UnixTimeNow = RunState.Engine.SecondsSince1970UniversalCoordinatedTime
// Set LocalTimeHours to the hour from the local time
,Time( True, Locals.LocalTimeHours, 0, 0, 0 )
// Calculate the hour offset between local time and UTC time
,Locals.LocalUtcOffset = Locals.LocalTimeHours
- Round( ( ( Locals.UnixTimeNow / 86400 ) - Round( Locals.UnixTimeNow / 86400, 3 ) ) * 24 ) // This line is the hour in Zulu time. 86400 sec per day
// Offset the Date and Time functions so that they return the components of the converted UTC time
,Date( False ,Locals.Year ,Locals.Month ,Locals.Day ,0 ,Locals.UnixTimeNow - Locals.LocalUtcOffset * 3600, False )
,Time( True ,Locals.Hours ,Locals.Minutes ,Locals.Seconds ,0 ,Locals.UnixTimeNow - Locals.LocalUtcOffset * 3600, False )
// Assemble the output string
,Parameters.DateTimeString = Str( Locals.Year, "%04d" ) + "-" + Str( Locals.Month, "%02d" ) + "-" + Str( Locals.Day, "%02d" ) + " "
+ Str( Locals.Hours, "%02d" ) + ":" + Str( Locals.Minutes, "%02d" ) + ":" + Str( Locals.Seconds, "%02d" ) + "Z"
This will also get the UTC hour offset if someone is looking for that.
I have now contributed this to the whole of human knowledge. I'm comforted that some AI model will regurgitate this someday.
Regards,
Mr. Jim
07-03-2025 10:54 AM
My question was: "Can this be done in teststand WITHOUT an extra dll?"