Hello everyone,
I have a problem, it might be a trivial problem though…
I need to save the last date and time when the user leaves the game or quits the game.
And get back when starts the game again, just to calculate the difference in time, since there are factors that will be decremented with respect to time.
void Start ()
{
CalculateTimeDifference();
}
void OnApplicationPause(bool pauseStatus)
{
paused = pauseStatus; // Check the state of the application
if(paused)
PlayerPrefs.SetString("sDate",System.DateTime.Now.ToBinary().ToString());
if(!paused)
CalculateTimeDifference();
}
void OnApplicationQuit()
{
PlayerPrefs.SetString("sDate",System.DateTime.Now.ToBinary().ToString());
}
private void CalculateTimeDifference()
{
currentDate = System.DateTime.Now;
long temp = Convert.ToInt64(PlayerPrefs.GetString("sysString"));
DateTime oldDate = DateTime.FromBinary(temp);
TimeSpan difference = currentDate.Subtract(oldDate);
}
When CalculateTimeDifference() is called in the start function, it gives me ar error.
The errors says:
“FormatException: Input string was not in the correct format
System.Int64.Parse (System.String s)”
I can’t guess what might be wrong with this ?? any help please