Retrieving DateTime

Hi there,
I am trying to get a DateTime figure from PlayerPrefs.

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()…

       PlayerPrefs.SetString("last_dateTime", System.DateTime.Now.ToBinary().ToString());

if you do

Debug.Log(PlayerPrefs.GetString("last_dateTime"));

whats the output?

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.

 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?