Hi
I have the following script to display real time date and time and works perfect but how do I add th or st or nd depending on the date, for example it currently read Monday January 9 2017 16:31:49 but be good if could be Monday January 9th 2017 16:31:49
The code is below
Thank you in advanceCode:function date_time(id) { date = new Date; year = date.getFullYear(); month = date.getMonth(); months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); d = date.getDate(); day = date.getDay(); days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); h = date.getHours(); if(h<10) { h = "0"+h; } m = date.getMinutes(); if(m<10) { m = "0"+m; } s = date.getSeconds(); if(s<10) { s = "0"+s; } function nth(d) { if(d>3 && d<21) return 'th'; // thanks kennebec switch (d % 10) { case 1: return "st"; case 2: return "nd"; case 3: return "rd"; default: return "th"; } } result = ''+days[day]+' '+months[month]+' '+d+' '+year+' '+h+':'+m+':'+s; document.getElementById(id).innerHTML = result; setTimeout('date_time("'+id+'");','1000'); return true; }



Reply With Quote



Bookmarks