How to get the current date or time
Monkey Forums/Monkey Beginners/How to get the current date or time
| ||
| Hi, I want to save some data in combination with the time to track the usage of the game. Is there a way to get the date/time of the system? Phil |
| ||
Local date:=GetDate() http://www.monkey-x.com/docs/html/Modules_mojo.app.html#GetDate |
| ||
| Also note that GetDate() returns an array, with 7 elements (0-6). They are in the order of year/month/day/hours/minutes/seconds/millisecs. Using the example that therevills said, you can access the elements like this: date[i]. Or you can access them like this: GetDate()[i] Each element is an integer. |
| ||
| Thank you very much. I should have read the docs more properly. Sometimes it's hard for me to get a good overview of what's available and how to use it, when consulting the docs. |
| ||
Here's a little help to see how to use it.
Function GetCurrentDateTime:String()
Local date:=GetDate()
Local months:=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
local day:int = date[2]
local month:int = date[1]
local year:int = date[0]
local hour:int = date[3]
local min:int = date[4]
local sec:int = date[5]
Print "Day: " + date[2]
Print "Month: " + date[1]
Print "Year: " + date[0]
Print "Hour: " + date[3]
Print "Min: " + date[4]
Print "Sec: " + date[5]
Local now:String = hour+":"+min+":"+sec+" "+day+" "+month+" "+year
Return now
End Function
I've posted some DateCalc functions to monkeycode recently. http://www.monkey-x.com/Community/posts.php?topic=10029 |