- Home /
check time since player last played the game ?
I want to save the time in in player prefs when a player quits the game, and when they start the game again check how many seconds have gone by since that saved time.
I know it has something to do with DateTime but I am not sure how to set it up.
Thanks in advance!
Answer by Montraydavis · Oct 27, 2012 at 04:54 PM
Assuming you already saved the last time variable, simply use the following
public float DifferenceTime = System.DateTime.Now - lastTimeSaved ;
Super easy :D
PS: You might want to take a look at the System DateTime docs for mono - http://www.go-mono.com/docs/index.aspx?link=T:System.DateTime
Yes, but the syntax will looks just a bit different, obviously.
Just make sure to
import System;
. Thumbs up if this solves your issue.
i will try it as soon as i can and get back to you. One more question is DateTime.Now a float representing the number of seconds since 1970? or am I thinking of something else.
I see now it isn't a float it's a variable that includes the whole date, i need to figure out how many $$anonymous$$utes it has been so i suppose ill just do the math using the date. thanks for your help
You are very welcome. Glad that this has helped you.
Your answer
![](https://koobas.hobune.stream/wayback/20220613082947im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Game structure: Time intervals, enemy speed, enemy quantity. How best to set this up? 1 Answer
Smaller Time Interval? 3 Answers
javascript System time and date? 3 Answers
How to get system time? 1 Answer
Accessing local system ( File Browser ) 2 Answers