Android - how to get the time paused and time since then

So im making a game where i need to have the application run in the background and earn the user “points”, and after some research Iv found out that’s obviously not possible on mobile. So the question is, how can i find out what the time is that the user quit, and what the time is when he comes back on, so that i can calculate what the user has made since leaving.

you dont actually need to have the app run in the background to accomplish this, you just need to have the app save the last date and time that it was open to playerprefs and when the app is reopened have it check the current date and time and calculate the difference.

Something like this,

    using UnityEngine;//Default
    using System.Collections;//Default
    using System;//for TimeDate stuff
    public class ExampleClass : MonoBehaviour {
        public TimeSpan timeDifference;//Amount of time since the game was last open
    	public DateTime currentTimeAndDate;
    	public DateTime lastSavedTimeAndDate;
    	void Start () {
    		currentTimeAndDate = DateTime.UtcNow;
    		lastSavedTimeAndDate = DateTime.Parse (PlayerPrefs.GetString ("lastSavedTimeAndDate"));
    		timeDifference = currentTimeAndDate - lastSavedTimeAndDate;
    		timeInSeconds = (float)timeDifference.TotalSeconds;
    	void Update () {
    		currentTimeAndDate = DateTime.UtcNow;
    		lastSavedTimeAndDate = currentTimeAndDate;
    		PlayerPrefs.SetString ("lastSavedTimeAndDate", lastSavedTimeAndDate.ToString ());

This is cut and pasted from one of my scripts that does the exact thing you need, but some of the variables may not be needed for your project, this is just to get you going in the right direction.

I had to remove bits and pieces from my code that werent relevant to your question so if I’m missing any curly braces or anything I apologize for that, but it looks to me like this should be fine.