Date format DD/MM/YYYY

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yas

    Date format DD/MM/YYYY

    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(TheD ate,e,top,left)
    {
    varActiveTBox = e
    varTop = top
    varLeft = left
    var RefDate = new Date(TheDate)
    varDays = RefDate.getTime () - (OneDay * (RefDate.getDat e()-1))
    RefDate.setTime (varDays)
    varDays = RefDate.getTime () - (OneDay * (RefDate.getDay ()))
    RefDate.setTime (varDays)
    var MnthDate = new Date(TheDate)
    varDays = RefDate.getTime () + (OneDay * 15)
    MnthDate.setTim e(varDays)
    varCurrentMonth = varMonth[MnthDate.getMon th()+1] + " " +
    MnthDate.getYea r()
    CurrentDate = TheDate
    ShowCalendar(Re fDate);
    }

    function Prev()
    {
    var pDate = new Date(CurrentDat e);
    varpDays = pDate.getTime() - OneMonth;
    pDate.setTime(v arpDays);
    DatePicker(pDat e,varActiveTBox ,varTop,varLeft );
    }

    function Next()
    {
    var nDate = new Date(CurrentDat e);
    varnDays = nDate.getTime() + OneMonth;
    nDate.setTime(v arnDays);
    DatePicker(nDat e,varActiveTBox ,varTop,varLeft );
    }

    function ShowCalendar(th eDate){
    calendar.innerH TML = "";
    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='calheade r'>" +
    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=ShowDat e('"
    varCal += DateLoop.getMon th()+1 + "/" + DateLoop.getDat e() +
    "/" +
    DateLoop.getYea r()
    varCal += "') class='calday'> " + DateLoop.getDat e() + "</td>";
    varDays = DateLoop.getTim e() + OneDay;
    DateLoop.setTim e(varDays);


    }
    varCal += "</tr>"
    }
    varCal += "</table>"
    calendar.innerH TML = varCal
    }

    function ShowDate(theDat e)
    {
    var myDate = new Date(theDate)

    calendar.innerH TML = ""
    varActiveTBox.v alue = theDate
    }
  • Erwin Moller

    #2
    Re: Date format DD/MM/YYYY

    Yas schreef:
    <snip>

    Hi Yas,

    We all saw your posting from 3 hours ago just fine.
    No need to repost the same question so fast.

    If you are lucky somebody fixes your code.
    I will not fix it because it is so basic.
    You should be able to do it yourself, which you didn't try.
    (At least you didn't show us anything.)

    I don't want to be rude, or lecture you, but....
    In general, just asking to fix your problem in a newgroup doesn't result
    in a solution/many responses.
    People think you are lazy, and should do it yourself.
    (We get paid most of the time to fix other peoples problems, you know..)

    However, if you ask something after trying yourself, AND show us what
    you tried, you might get much better responses.

    (Just a freindly word of advise.)

    Regards,
    Erwin Moller

    Comment

    Working...