Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Time and date in HTML code

  • 31-05-2004 06: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, Paid Member Posts: 44,224 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>

    Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/ .



  • Moderators, Politics Moderators, Paid Member Posts: 44,224 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.

    Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/ .



  • Closed Accounts Posts: 158 ✭✭wheelbarrow


    ..cheers,

    date going in ok - time doesnt appear???

    Am i fecking up??


  • Moderators, Politics Moderators, Paid Member Posts: 44,224 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>

    Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/ .



Advertisement