Is there a way to grab the time of day that is on the system itself? It would be very helpful to be able to use that information, if it’s even possible. If it’s possible, can I also take the day, month, and/or year?
System.DateTime
–Eric
Ah thanks for the quick response. I shall try this.
It is complaining…
Assets/Scripts/GUI/TimeTest.js(3,60): BCE0020: An instance of type ‘Date’ is required to access non static member ‘ToString’.
function OnGUI () {
GUI.Label(Rect(10, 200, 100, 100), System.DateTime.ToString());
}
Use the actual property in System.DateTime that you want.
–Eric
Ok, im completely lost… Is there no simple JavaScript command that can draw that info out?
No, Unity uses .net (actually Mono). You can access it all in Javascript, but you need to become familiar with it because that’s where all non-Unity-specific functionality comes from. e.g.,
print (System.DateTime.Now);
See the link above for day/month/year/etc. functionality.
–Eric
I’m guessing this is a CSharp thing?
No…as I said, it’s .net/Mono. It’s not language-related in any way. Mono is what Unity is built on; anything you write in any of the 3 languages compiles to the same CIL code, and all .net functionality is available in all languages.
–Eric
so… whats a code that will get the time on the system and put it out on the screen as a GUI.Label?
It is working for me.
thats excellent. thats much!!
ok so as far as I can tell, i can only use this with “print ();” and “Debug.Log();” (which are practically the same thing). But I cannot use it with “GUI.Label();”…
kinda depressing…
System.DateTime.Now.ToString()
ok these are basics…i should have thought about most of these…
ok so what are the variations? This code shows date and time. What can I do to show the date and time seperately on different parts of the screen? Also, How do I round it off to just hh/mm/ss? And switch between military and civilian time?
Also, am i keeping you busy?
System.DateTime.Now.TimeOfDay.ToString()
(Hours, minutes, seconds, miliseconds)
System.DateTime.Now.Month.ToString()
(Should I explain this one :lol:
Since we have monodevelop, it is simply a matter of typing ‘.’ after a keyword!
how do I get it to omit the milliseconds?
Good question!
ah ok. well this thread has been extremely helpful. Plenty of new techniques and extra functions to look in to.
Oh, and no, the rest is not important.