Hi there, I am trying to get a DateTime figure from PlayerPrefs. Code (csharp): long temp = Convert.ToInt64(PlayerPrefs.GetString("last_dateTime")); I am not sure if my approach is incorrect, or there is some abnormailirty, because at this point, I have not saved a "last_dateTime", yet. My error is this.. I save the date time like this, on Quit()... Code (csharp): PlayerPrefs.SetString("last_dateTime", System.DateTime.Now.ToBinary().ToString());
Alright, I did some searching on the interwebs through some C# documentation and found someone asking a similar question to you though outside the bounds of unity. I tested this and the conversion seems to work perfectly, not that i really understand it, something with the "O" and how that is handled with parsing. Code (csharp): using UnityEngine; using System.Collections; using System; using System.Globalization; public class DateTimeConversion : MonoBehaviour { // Use this for initialization void Start () { const string FMT = "O"; DateTime now1 = DateTime.Now; string strDate = now1.ToString(FMT); DateTime now2 = DateTime.ParseExact(strDate, FMT, CultureInfo.InvariantCulture); Debug.Log(now1); Debug.Log(now2); } }
you can set a default value for your "Getstring" : long temp = Convert.ToInt64(PlayerPrefs.GetString("last_dateTime",System.DateTime.Now.ToBinary().ToString()));
I am trying to exactly the same thing and getting exactly the same error. Can you remember how you solved this?