Answer the question
In order to leave comments, you need to log in
How to save date in Unity to Json file?
Good afternoon, at the moment I'm trying to save the date to the file so that when I enter the game, a message appears about the date of the last entry into the game, however, when the date is pulled out of the file, the initial date is obtained (01.01.0001 0:00:00), do not tell me what problem? If anything, the DataSave method saves the date to the file.
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TEST : MonoBehaviour
{
string name_file;
private void Start()
{
name_file = Path.Combine(Application.dataPath, "SaveDate.json");
if (File.Exists(name_file))
{
Debug.Log(JsonUtility.FromJson<DateTime>(File.ReadAllText(name_file)));
}
}
public void DataSave()
{
Debug.Log(DateTime.Now);
File.WriteAllText(name_file, JsonUtility.ToJson(DateTime.Now));
}
public void Delete()
{
File.Delete(name_file);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question