saving and loadong data unity code example

Example 1: unity how to get data of play session time in a text file?

string path = Application.dataPath + "/Data/DataLog.txt";

        if (!File.Exists(path))
        {
            File.WriteAllText(path, "Level Test1 \n\n");
        }

        string date = "Login Date: " + System.DateTime.Now + "\n";
        string timed = "Session Time: " + System.Timers.Timer;

        File.AppendAllText(path, date);

Example 2: unity persistent data

private int health;

private void Load()
{
    if(PlayerPrefs.HasKey("health"))
    {
        health = PlayerPrefs.GetInt("health");
    }
}

private void Save()
{
    PlayerPrefs.SetInt("health", health);
    PlayerPrefs.Save();
}