Hello, I’m struggling in TimeSpan class’s error on ios platform(System.TimeSpan).
Whenever I use TimeSpan.FromSeconds, it throws out outside range exception [MinValue, MaxValue],
so I tried to show the two values.
Just use
Debug.Log(TimeSpan.MinValue.TotalSeconds.ToString() + "," + TimeSpan.MaxValue.TotalSeconds.ToString());
In editor, it prints the right value which is “-922337203685.478,922337203685.478”.
But on ios, the same code prints “4.0917397079469E+142,4.0917397079469E+142”, that’s really not right, and I guess it is this bug which caused the exception.
I know I can write a timespan class by myself but I’m wondering if I did something wrong because I cannot see anyone else find the same bug, or it is really a bug.
OK, bug confirmed in Unity 4.3.1f1.
Because I have a slow mac and a fast pc, I always build XCode project on PC and transfer it to Mac to build on ios.
This bug will occur if you build xCode project using Windows Unity Editor, maybe as I said the ticks base is different on Windows and iOS. I’ve reported this bug to Unity team.
I went for an interesting approach 
Create a class and have a function to get the Unix Time natively and include that in your IOS project. Call the function from your C# script.
Function in Objective C:
extern “C” {
double dateToUnixTimestamp() {
return [[NSDate date] timeIntervalSince1970];
}
}
C# Implementation:
#if UNITY_IOS
[DllImport(“__Internal”)]
private static extern double dateToUnixTimestamp();
public Int32 DateToUnixTimestamp() {
return (Int32)dateToUnixTimestamp();
}
#else
public Int32 DateToUnixTimestamp() {
return (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
}
#endif