kannan D.S kannan D.S - 5 months ago 15
jQuery Question

How to show current date and time like 11 December 2015 11:20 AM using jquery, AM needs to show like superscript

enter image description here

How to show current date and time like 11 December 2015 11:20 AM using jQuery, AM needs to show like superscript.please check my fiddle and image http://fiddle.jshell.net/kannankds/qtrnzsp6/

<div>
<asp:Label ID="cTime" runat="server" ClientIDMode="Static" BackColor="#ffff00"
Font-Bold="true" />
</div>

Answer

Same way but little more as you wanted.

$(document).ready(function()
{
var d = new Date();
var month = d.getMonth(); //Removed +1
var day = d.getDate();
var year = d.getFullYear();
var months = ['January','February','March','April','May','June','July','August','Septempber','October','November','December'];
var minutes = d.getMinutes().toString().length == 1 ? '0'+d.getMinutes() : d.getMinutes();
var hours = d.getHours().toString().length == 1 ? '0'+d.getHours() : d.getHours();
var ampm = d.getHours() >= 12 ? '<sup>PM<sup>' : '<sup>AM<sup>';
document.getElementById("time").innerHTML = d.getDate() + ' ' + months[month]+' '+d.getFullYear()+' '+hours +':'+minutes + ' ' + ampm;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="time"></div>

Comments