By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,960 Members | 1,453 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,960 IT Pros & Developers. It's quick & easy.

Date format

P: n/a
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 JScript to also use that
format.

Many thanks

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
}
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In comp.lang.javascript message <dd5b4839-f511-43de-8db2-03947e7321f5@b6
4g2000hsa.googlegroups.com>, Fri, 18 Apr 2008 01:19:16, Yas
<ya****@gmail.composted:
>Hello I've got the following Javascript for a web calendar popup that
outputs the date in 4/24/2008 (m/d/yyyy).
It's rubbish. Delete it.
Firefox is 2.0.0.14

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.