Y
Yas
Hello I've got the following Javascript for a web calendar popup that
outputs the date in 4/24/2008 (m/d/yyyy).
How can i modify it to output dd/mm/yyyy e.g. 24/04/2008. So all
outputs are in this format. The system this runs on has the correct
date format (not US) so I would like the JavaScript to also use that
format.
Many thanks
The code
------------------------------------
var OneDay = 86400000
var OneMonth = (OneDay * 30)
var CurrentDate = new Date()
varCurrentMonth = ""
varMonth = new Array(12)
varMonth[1] = "January"
varMonth[2] = "February"
varMonth[3] = "March"
varMonth[4] = "April"
varMonth[5] = "May"
varMonth[6] = "June"
varMonth[7] = "July"
varMonth[8] = "August"
varMonth[9] = "September"
varMonth[10] = "October"
varMonth[11] = "November"
varMonth[12] = "December"
varActiveTBox = ""
varTop = "100"
varLeft = "100"
function DatePicker(TheDate,e,top,left)
{
varActiveTBox = e
varTop = top
varLeft = left
var RefDate = new Date(TheDate)
varDays = RefDate.getTime() - (OneDay * (RefDate.getDate()-1))
RefDate.setTime(varDays)
varDays = RefDate.getTime() - (OneDay * (RefDate.getDay()))
RefDate.setTime(varDays)
var MnthDate = new Date(TheDate)
varDays = RefDate.getTime() + (OneDay * 15)
MnthDate.setTime(varDays)
varCurrentMonth = varMonth[MnthDate.getMonth()+1] + " " +
MnthDate.getYear()
CurrentDate = TheDate
ShowCalendar(RefDate);
}
function Prev()
{
var pDate = new Date(CurrentDate);
varpDays = pDate.getTime() - OneMonth;
pDate.setTime(varpDays);
DatePicker(pDate,varActiveTBox,varTop,varLeft);
}
function Next()
{
var nDate = new Date(CurrentDate);
varnDays = nDate.getTime() + OneMonth;
nDate.setTime(varnDays);
DatePicker(nDate,varActiveTBox,varTop,varLeft);
}
function ShowCalendar(theDate){
calendar.innerHTML = "";
var DateLoop = new Date(theDate);
var varCal ="<table border='0' cellspacing='2' cellpadding='1'
class='calendar' style='left: " + varLeft + "px; TOP: " + varTop +
"px'>";
varCal += "<tr><td onClick=Prev() class='clicker'><</td>";
varCal += "<td colspan='5' align='center' class='calheader'>" +
varCurrentMonth +"</td>";
varCal += "<td onClick=Next() class='clicker'>></td></tr>";
for ( var r = 1; r <= 6; r++ ) {
varCal += "<tr>"
for ( var c = 1; c <= 7; c++ ) {
varCal += "<td align='right' onClick=ShowDate('"
varCal += DateLoop.getMonth()+1 + "/" + DateLoop.getDate() +
"/" +
DateLoop.getYear()
varCal += "') class='calday'>" + DateLoop.getDate() + "</td>";
varDays = DateLoop.getTime() + OneDay;
DateLoop.setTime(varDays);
}
varCal += "</tr>"
}
varCal += "</table>"
calendar.innerHTML = varCal
}
function ShowDate(theDate)
{
var myDate = new Date(theDate)
calendar.innerHTML = ""
varActiveTBox.value = theDate
}
outputs the date in 4/24/2008 (m/d/yyyy).
How can i modify it to output dd/mm/yyyy e.g. 24/04/2008. So all
outputs are in this format. The system this runs on has the correct
date format (not US) so I would like the JavaScript to also use that
format.
Many thanks
The code
------------------------------------
var OneDay = 86400000
var OneMonth = (OneDay * 30)
var CurrentDate = new Date()
varCurrentMonth = ""
varMonth = new Array(12)
varMonth[1] = "January"
varMonth[2] = "February"
varMonth[3] = "March"
varMonth[4] = "April"
varMonth[5] = "May"
varMonth[6] = "June"
varMonth[7] = "July"
varMonth[8] = "August"
varMonth[9] = "September"
varMonth[10] = "October"
varMonth[11] = "November"
varMonth[12] = "December"
varActiveTBox = ""
varTop = "100"
varLeft = "100"
function DatePicker(TheDate,e,top,left)
{
varActiveTBox = e
varTop = top
varLeft = left
var RefDate = new Date(TheDate)
varDays = RefDate.getTime() - (OneDay * (RefDate.getDate()-1))
RefDate.setTime(varDays)
varDays = RefDate.getTime() - (OneDay * (RefDate.getDay()))
RefDate.setTime(varDays)
var MnthDate = new Date(TheDate)
varDays = RefDate.getTime() + (OneDay * 15)
MnthDate.setTime(varDays)
varCurrentMonth = varMonth[MnthDate.getMonth()+1] + " " +
MnthDate.getYear()
CurrentDate = TheDate
ShowCalendar(RefDate);
}
function Prev()
{
var pDate = new Date(CurrentDate);
varpDays = pDate.getTime() - OneMonth;
pDate.setTime(varpDays);
DatePicker(pDate,varActiveTBox,varTop,varLeft);
}
function Next()
{
var nDate = new Date(CurrentDate);
varnDays = nDate.getTime() + OneMonth;
nDate.setTime(varnDays);
DatePicker(nDate,varActiveTBox,varTop,varLeft);
}
function ShowCalendar(theDate){
calendar.innerHTML = "";
var DateLoop = new Date(theDate);
var varCal ="<table border='0' cellspacing='2' cellpadding='1'
class='calendar' style='left: " + varLeft + "px; TOP: " + varTop +
"px'>";
varCal += "<tr><td onClick=Prev() class='clicker'><</td>";
varCal += "<td colspan='5' align='center' class='calheader'>" +
varCurrentMonth +"</td>";
varCal += "<td onClick=Next() class='clicker'>></td></tr>";
for ( var r = 1; r <= 6; r++ ) {
varCal += "<tr>"
for ( var c = 1; c <= 7; c++ ) {
varCal += "<td align='right' onClick=ShowDate('"
varCal += DateLoop.getMonth()+1 + "/" + DateLoop.getDate() +
"/" +
DateLoop.getYear()
varCal += "') class='calday'>" + DateLoop.getDate() + "</td>";
varDays = DateLoop.getTime() + OneDay;
DateLoop.setTime(varDays);
}
varCal += "</tr>"
}
varCal += "</table>"
calendar.innerHTML = varCal
}
function ShowDate(theDate)
{
var myDate = new Date(theDate)
calendar.innerHTML = ""
varActiveTBox.value = theDate
}