Get current date and time.
Hello,
How can I get current date and time on the device that the application is running?
Thanks!
7 Answers
-
try it like this:
function getDate(0 { var currentTime = new Date(); var hours = currentTime.getHours(); var minutes = currentTime.getMinutes(); var month = currentTime.getMonth() + 1; var day = currentTime.getDate(); var year = currentTime.getFullYear(); return month+"/"+day+"/"+yeah+" - "hours +":"+minutes; }
if you call the function getDate(); it will print teh date/time like this: 3/30/2010 - 13:27
-
I haven't had any problems at all using the javascript Date object:
var d = new Date(); var day = d.getDate(); var month = d.getMonth() + 1; var year = d.getFullYear();
-
I cleaned up the getDate() function:
function getDate() { var currentTime = new Date(); var hours = currentTime.getHours(); var minutes = currentTime.getMinutes(); var seconds = currentTime.getSeconds(); var month = currentTime.getMonth() + 1; var day = currentTime.getDate(); var year = currentTime.getFullYear(); if (hours < 10) { hours = "0" + hours}; if (minutes < 10) { minutes = "0" + minutes}; if (seconds < 10) { seconds = "0" + seconds}; return month + "/" + day + "/" + year + " - " + hours + ":" + minutes + ":" + seconds; }
-
Thanks,
I have just tested this on a device. I have changed date, time and timezone few times and it is working as expected.
-
Hi
I use the following reference:
http://www.quackit.com/javascript/javascript_date_and_time_functions.cfm
Check it out!
-
But however thanks for posting the solution.
-
I have done this with form builder.