Sunday, 27 January 2013 13:54

how to get client computer date and time using javascript

Written by 
Rate this item
(0 votes)

It's needed to get the current date and time of the user
computer for processing using javascript.

following are the javascript codes to achieve this properly -

window.onload = function () {
var dayarray = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday")

var montharray = new Array("January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December")

var mydate = new Date()
var year = mydate.getYear()
if (year < 1000)
year += 1900
var day = mydate.getDate()
var month = mydate.getMonth()
var daym = mydate.getDate()
if (daym < 10)
daym = "0" + daym
var hours = mydate.getHours()
var minutes = mydate.getMinutes()
var seconds = mydate.getSeconds()
var dn = ""
if (minutes <= 9)
minutes = "0" + minutes
if (seconds <= 9)
seconds = "0" + seconds
var cdate = "";
cdate = month + 1 + "/" + day + "/" + year + " " + hours + ":" + minutes + ":" + seconds; // +" " + dn;
alert(cdate);
}

Read 2860 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.
Login to post comments