- Home /
The question is answered, right answer was accepted
read Time and Date
Hi there, iam a freshman in using UNITY3D and i need for a project to read out the system time and date of the computer my game is running on. is there any way in java, c, or boo to do this?
lots of thanks ThisIsTom
Have any of you tried it in developement build? Because I just realized, that from the build I get the date and time of the creation, not the current. Anyone knows why it could happen? It's not the code, I'm shure, but had anyone ever had it, and know what caused it?
Answer by duck · Jan 07, 2010 at 11:45 PM
Yes, you have access to most of the .net classes including the System.DateTime structure, and more specifically you can get the current date and time using the DateTime.now property.
thanks for the answer, but if i try to read out the date in form "print(DateTime.now);" unity says - $$anonymous$$ identyfier DateTime -. what dit i wrong? thx ThisIs$$anonymous$$
Ah yes, "DateTime" is part of .Net's System class which isn't included by default. You can fix this two ways: either change it to System.DateTime.now everywhere you use it, or add using System; at the top of your c# script (or in JS, add import System; at the top). Duck 1 $$anonymous$$ ago
i just tried out that System.DateTime.now and unity said 'now' is not a mamber of Date; did you mean: 'Now' so the real version of the JS is var systemTime = System.DateTime.Now;
Answer by Michael Neely · Oct 20, 2010 at 02:19 AM
This may help. Try using variables like these and see how it goes. You do have to
theTime = System.DateTime.Now.ToString("hh:mm:ss"); theDate = System.DateTime.Now.ToString("MM/dd/yyyy"); theMonth = System.DateTime.Now.get_Month(); theDay = System.DateTime.Now.get_Day();
I try to do it, but I don't see saved data
PlayerPrefs.SetString("date time" System.DateTime.Now.ToString("yyyy/$$anonymous$$$$anonymous$$/dd HH:mm:ss"));
Debug.Log(PlayerPrefs.GetString("date time"));
Here what it show: UnityEngine.Debug:Log(Object)
after set something use PlayerPrefs.Save(); for saving it.
Answer by MinhajJaved · Feb 10, 2017 at 09:17 AM
@dmitry-kozyr try this PlayerPrefs.SetString("date_time", System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); Debug.Log(PlayerPrefs.GetString("date_time"));
Not only is it 7 y/o question, but the answer isn't correct.