Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Time and date in HTML code

Options
  • 31-05-2004 6:13pm
    #1
    Closed Accounts Posts: 158 ✭✭


    Does anyone know the code to input the time and date into a site.

    Cheers


Comments

  • Moderators, Politics Moderators Posts: 39,939 Mod ✭✭✭✭Seth Brundle


    <script language="JavaScript" type="text/javascript">
    <!--
    TheDate = new Date();
    var Months=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
    var Days= new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
    wd = TheDate.getDay();
    //Convert digit to string
    wd = Days[wd];
    d = TheDate.getDate();
    //Append zero to one-digit date for consistency
    if (d < 10)
    {d = "0" + d;}
    m = TheDate.getMonth();
    m = Months[m];
    y = TheDate.getFullYear();
    dstring = ""+wd+"" + " " + ""+d+"" + " " + ""+m+"";
    document.write(dstring);
    //-->
    </script>


  • Moderators, Politics Moderators Posts: 39,939 Mod ✭✭✭✭Seth Brundle


    I should have added - that is Client Side JavaScript and will therefore use the time on the users computer rather than the time on your web server.


  • Closed Accounts Posts: 158 ✭✭wheelbarrow


    ..cheers,

    date going in ok - time doesnt appear???

    Am i fecking up??


  • Moderators, Politics Moderators Posts: 39,939 Mod ✭✭✭✭Seth Brundle


    sorry - forgot time bit - try this:-
    <script language="JavaScript" type="text/javascript">
    <!--
    TheDate = new Date();
    var Months=new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    var Days= new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday","Sunday");
    wd = TheDate.getDay();
    //Convert digit to string
    wd = Days[wd];
    d = TheDate.getDate();
    //Append zero to one-digit date for consistency
    if (d < 10)
    {d = "0" + d;}
    m = TheDate.getMonth();
    m = Months[m];
    y = TheDate.getFullYear();

    var theTime = new Date();
    var Hours;
    var Mins;
    var Time;
    Hours = theTime.getHours();
    if (Hours >= 12) {
    Time = " P.M.";
    }
    else {
    Time = " A.M.";
    }

    if (Hours > 12) {
    Hours -= 12;
    }

    if (Hours == 0) {
    Hours = 12;
    }

    Mins = theTime.getMinutes();

    if (Mins < 10) {
    Mins = "0" + Mins;
    }

    document.write( wd + " " + d + " " + m+" ");
    document.write(Hours + ":" + Mins + Time + '');

    //-->
    </script>


Advertisement