The problem with JsonUtility, is that it doesn't save properties, just public fields and fields with the [SerializeField] attribute.
You can solve this with another class and some conversion magic, like so:
Json Serializable Class
[Serializable]
struct JsonDateTime {
public long value;
public static implicit operator DateTime(JsonDateTime jdt) {
Debug.Log("Converted to time");
return DateTime.FromFileTimeUtc(jdt.value);
}
public static implicit operator JsonDateTime(DateTime dt) {
Debug.Log("Converted to JDT");
JsonDateTime jdt = new JsonDateTime();
jdt.value = dt.ToFileTimeUtc();
return jdt;
}
}
Usage example
var time = DateTime.Now;
print(time);
var json = JsonUtility.ToJson((JsonDateTime) time);
print(json);
DateTime timeFromJson = JsonUtility.FromJson<JsonDateTime>(json);
print(timeFromJson);
Output
