Script working on PC and in editor but not on android

I have a script that manages an energy system that replenishes every once in awhile. This code works fine for the exe and in the editor but will not run properly on android. The only functions that works as intended are those that don’t involve time.Calling the functions from another script also did not work. Is there any way to fix this? Is DateTime.Now not compatible with android?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using System;

public class Survivors : MonoBehaviour
{
    float rechargeTime;
    DateTime currentTime;
    DateTime lastChecked;
    DateTime lastRefill;
    int elapsedHour,elapsedMin;
    int survivorsToAdd;

    // Use this for initialization
    void Awake ()
    {
        makeUpForLostTime();
        checkSurvivors();
    }
 
    // Update is called once per frame
    void Update ()
    {
        checkSurvivors();
    
    }

    public void Ok()
    {
        GameObject.Find("NMS_Canvas").gameObject.SetActive(false);
    }

    public void checkSurvivors()
    {
        GameObject temp = GameObject.Find("Energy");
        temp.GetComponent<Text>().text = "x " + PlayerPrefs.GetInt("currSurvivors") + "/" + PlayerPrefs.GetInt("maxSurvivors");
        if (PlayerPrefs.GetInt("currSurvivors")> PlayerPrefs.GetInt("maxSurvivors"))
        {
            temp.GetComponent<Text>().text = "x " + PlayerPrefs.GetInt("maxSurvivors") + "/" + PlayerPrefs.GetInt("maxSurvivors");
        }

    }

    IEnumerator compareTime()
    {
        yield return new WaitForSeconds(1f);

        currentTime = DateTime.Now;
        lastRefill = Convert.ToDateTime(PlayerPrefs.GetString("lastRefill"));
        TimeSpan difference = currentTime - lastRefill;
        if (difference.Minutes >= PlayerPrefs.GetInt("SurvivorRefreshTime") && PlayerPrefs.GetInt("currSurvivors") <= PlayerPrefs.GetInt("maxSurvivors"))
        {
            PlayerPrefs.SetString("lastRefill", System.DateTime.Now.ToString());
            PlayerPrefs.SetInt("currSurvivors", PlayerPrefs.GetInt("currSurvivors") + 1);//add one survivor
            Debug.Log("Add one survivor");
        }
        Debug.Log(difference);
        int seconds = (59 - difference.Seconds);
        string secondsText=seconds.ToString();
        if (seconds<10)
        {
            secondsText = "0" + seconds;
        }
        GameObject.Find("More in").GetComponent<Text>().text = "More In: " + (PlayerPrefs.GetInt("SurvivorRefreshTime")+ -difference.Minutes-1) + ":" + secondsText;
        StartCoroutine(compareTime());
    }


    public void makeUpForLostTime()
    {
    
        lastChecked = Convert.ToDateTime(PlayerPrefs.GetString("lastRecordedTime"));
        Debug.Log(lastChecked);
        DateTime currTime = DateTime.Now;
        Debug.Log(currTime);
        TimeSpan difference = currTime - lastChecked;
        Debug.Log(difference);
        elapsedHour = difference.Hours;
        elapsedMin = difference.Minutes;
        while (elapsedHour>0)
        {
            elapsedMin += 60;
            elapsedHour--;
        }

        if (elapsedMin> PlayerPrefs.GetInt("SurvivorRefreshTime")&& elapsedMin>0)
        {
            survivorsToAdd = elapsedMin / PlayerPrefs.GetInt("SurvivorRefreshTime");
        }

        int tempCurr = PlayerPrefs.GetInt("currSurvivors");
        int tempMax = PlayerPrefs.GetInt("maxSurvivors");


        while ( tempCurr <= tempMax && survivorsToAdd>0)
        {
            tempCurr++;
            Debug.Log("Making up for lost time");
            survivorsToAdd--;
        }
        PlayerPrefs.SetInt("currSurvivors", tempCurr);

        StartCoroutine(compareTime());
    }
}

There is nothing wrong with DateTime on Android to my knowledge. What are you getting when you log currTime?

Also, just as a note, you should do something about those GameObject.Find calls. They are very slow and especially needing to do it in update. Even caching the value would be better than having to do it every frame.

currTime displays the correct time in the debug log.

On my android device the console from android studio displays:

FormatException: String was not recognized as a valid DateTime.
at System.DateTime.Parse (System.String s, IFormatProvider provider, DateTimeStyles styles) [0x00000] in :0
at System.DateTime.Parse (System.String s, IFormatProvider provider) [0x00000] in :0
at System.DateTime.Parse (System.String s) [0x00000] in :0
at System.Convert.ToDateTime (System.String value) [0x00000] in :0
at Survivors.makeUpForLostTime () [0x00000] in :0
at Survivors.Awake () [0x00000] in :0

Looks like the string you’re converting to a datetime is not valid. Where are you saving your lastRecordedTime playerPref? You might try saving it in a different format. If you’re just using ToString() on the datetime, perhaps try one of the other conversions.

It works now when i changed to ToString() to DateTime.Parse(). Thanks