Jump to content
The simFlight Network Forums

Problem getting Zulu Date & Time


CXA001
 Share

Recommended Posts

While I have no problems getting the local date and time from the flight simulator, I am having an issue trying to get the zulu (or GMT) data and time from the flight simulator.

Here is my code (C#):

Offset<byte[]> FSUIPCGMTDateTime = new Offset<byte[]>("FSUIPCGMTDateTime", 0x023B, 10);

string stringFSGMTDateTime; 
string stringFSGMTDate;
string stringFSGMTTime;


FSUIPCConnection.Process(new string[] {"FSUIPCGMTDateTime" });
              
short GMTYear = BitConverter.ToInt16(FSUIPCGMTDateTime.Value, 8);
DateTime FSGMTTime = new DateTime(GMTYear, 1, 1, FSUIPCGMTDateTime.Value[0], FSUIPCGMTDateTime.Value[1], FSUIPCGMTDateTime.Value[2]);
short GMTDayNo = BitConverter.ToInt16(FSUIPCGMTDateTime.Value, 6);
FSGMTTime = FSGMTTime.Add(new TimeSpan(GMTDayNo - 1, 0, 0, 0));
stringFSGMTDateTime = "[" + FSGMTTime.ToString("yyyy/MM/dd HH:mm") + "]";
stringFSGMTDate = FSGMTTime.ToString("yyyy MM dd");
stringFSGMTTime = FSGMTTime.ToString("HH:mm");

I should be getting something like:
[2016/07/14 22:13]

What I am getting is:
[1801/12/05 22:13]

What am I missing?

 

 

Link to comment
Share on other sites

Quote

Offset<byte[]> FSUIPCGMTDateTime = new Offset<byte[]>("FSUIPCGMTDateTime", 0x023B, 10);

short GMTYear = BitConverter.ToInt16(FSUIPCGMTDateTime.Value, 8);
short GMTDayNo = BitConverter.ToInt16(FSUIPCGMTDateTime.Value, 6);

The year starts at offset 0x2040 which is 5 bytes in from 0x023B. So this line should be:

short GMTYear = BitConverter.ToInt16(FSUIPCGMTDateTime.Value, 5); 

The day number is 3 bytes in:

short GMTDayNo = BitConverter.ToInt16(FSUIPCGMTDateTime.Value, 3); 

Looks like you were counting the first 3 time offsets in that block as 2 bytes each.

Paul

Link to comment
Share on other sites

  • 1 year later...

Hi Paul,

I have a problem with Zulu Time and Local Time :

I choose an airport on US, (KVPS for example)

Local Time = 30 may 2017 18:59:30

Zulu Time = 30 may 2017 23:59:30

and have a timer to update values each second. All is ok but when Zulu Time = 31 may 2017 00:00:01, date for Local Time is now =31 may 2017 19:00:01. For Local Time date must be 30 may and not 31 may.

Here is the code :
       

private Offset<byte[]> fsLocalDateTime = new Offset<byte[]>(0x0238, 10);
        private Offset<byte[]> fsZuluDateTime = new Offset<byte[]>(0x023B, 10);

        private Offset<byte> zmin = new Offset<byte>(0x23c);
        private Offset<byte> zhour = new Offset<byte>(0x23b);
        private Offset<byte> second = new Offset<byte>(0x23a);


        private void timer1_Tick(object sender, EventArgs e)
        {
            // Process the default group
            try
            {
                FSUIPCConnection.Process();

                // get local Time
                short year = BitConverter.ToInt16(fsLocalDateTime.Value, 8);
                DateTime fsTime = new DateTime(year, 1, 1, fsLocalDateTime.Value[0], fsLocalDateTime.Value[1], fsLocalDateTime.Value[2]);
                short dayNo = BitConverter.ToInt16(fsLocalDateTime.Value, 6);
                fsTime = fsTime.Add(new TimeSpan(dayNo - 1, 0, 0, 0));
                lblLocalTime.Text = (fsTime.ToString("F", CultureInfo.CreateSpecificCulture("fr-FR")));

                // get Zulu Time
                short year2 = BitConverter.ToInt16(fsZuluDateTime.Value, 5);
                DateTime fsZuluTime = new DateTime(year2, 1, 1, zhour.Value, zmin.Value, second.Value);
                short zuludayNo = BitConverter.ToInt16(fsZuluDateTime.Value, 6);
                fsZuluTime = fsZuluTime.Add(new TimeSpan(dayNo - 1, 0, 0, 0));
                lblZuluTime.Text = (fsZuluTime.ToString("F", CultureInfo.CreateSpecificCulture("fr-FR")));

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error : " + ex.Message);
            }

       }

 

Thank you for your help.

Link to comment
Share on other sites

Hi,

Here's some code that will get both Zulu and Local into a .net DateTime. (This works with FSUIPC3 as well as it doesn't use any of the new date/time fields in FSUIPC4).

        private Offset<ushort> zuluYear = new Offset<ushort>("DateTime", 0x0240);
        private Offset<ushort> zuluDayNumber = new Offset<ushort>("DateTime", 0x023E);
        private Offset<byte> zuluHour = new Offset<byte>("DateTime", 0x023B);
        private Offset<byte> zuluMin = new Offset<byte>("DateTime", 0x023C);
        private Offset<byte> zuluSec = new Offset<byte>("DateTime", 0x023A);
        private Offset<short> localOffset = new Offset<short>("DateTime", 0x0246);
FSUIPCConnection.Process("DateTime");
// Create datetime for Zulu
DateTime zuluDateTime = new DateTime(zuluYear.Value, 1, 1, zuluHour.Value, zuluMin.Value, zuluSec.Value).AddDays((double)(zuluDayNumber.Value - 1));
// Create datetime for Local
DateTime localDateTime = zuluDateTime.AddMinutes(localOffset.Value * -1);

 

Paul

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.