Input string was not in a correct format.

May 4, 2009 at 1:15 PM
Hello,

I would like to know why i get the message: 'Input string was not in a correct format.' in the column 'Uptime', even for the computer where i run the program.
What's the problem ? Can we fix this ?

Thanks.





Nov 13, 2009 at 6:23 AM

      private static DateTime GetLocalTimeFromWmiDate(string lastBootUpTime)
      {
            // BUG: Here you get an error if the sign '-' is not present in the string. This is the case of a positive offset
            //int utcMinuteOffset = int.Parse(lastBootUpTime.Substring(lastBootUpTime.IndexOf('-') + 1)); 

            // FIX: Check the kind of sign in the string, before do the Parse
            int utcMinuteOffset;
            if (lastBootUpTime.Contains("-"))
            {
                utcMinuteOffset = int.Parse(lastBootUpTime.Substring(lastBootUpTime.IndexOf('-') + 1));
            }
            else
            {
                utcMinuteOffset = int.Parse(lastBootUpTime.Substring(lastBootUpTime.IndexOf('+') + 1));
            }

Regards.