Hello community,
I am currently searching for a way to grab the current date from the device (iphone, ipod touch). Is there an API call that somehow I missed in the documentation? I do not see this in the iPhone Settings documentation. I know I can easily do this with a simple WWW object and call to a site with the date, but I want the functionality even when the user is not connected to a network (using an ipod touch). This is a crucial part of our game at the moment. Thanks in advance.
~Corey~
I’m not sure how to do this in Unity. Here is one way to do it using Objective-C: Use the NSDateFormatter setDateFormat and define it the way you would like the date to appear in your iPhone app.
If it has to be a unity API, then I do not know the answer.
Ok so here’s why I need the date. We want to stamp the date as our user gets a new high score from the game. The reason why we do this is so that when they send their scores to the server we can check the date of their achieved score against the current date of the server and validate it. This validation process is unique to our game because we are giving away weekly and monthly prizes and we are going to fail the user’s submission if their achieved score date is from a past week/month.
~Corey~
here is a script i had written (mostly copied from something else in this forum ) to get the date from the iphone. I actually tried it just in the editor of unity Iphone, but it should work on the device to. Hope it helps!
The script get’s the actual time to.
import System;
var displayTime : GUIText;
var displayDate : GUIText;
var actualTime = DateTime.Now.ToString("hh:mm:ss");
var date = DateTime.Now.ToString("mm:dd:yyyy");
function Update () {
actualTime = DateTime.Now.ToString("hh:mm:ss");
date = DateTime.Now.ToString("dd/MM/yyyy");
//var timeNow : DateTime = DateTime.Now;
displayDate.text = date;
displayTime.text = actualTime;
}
Thanks taio for your reply. We ended up using a very similar way to grab the date from the device. Appreciate all the help.
~Corey~
The other option for this is to grab the date from the server as you commit a score to the DB.