Format date and Time using Jquery

Ankaprasad
Posted by Ankaprasad under jQuery category on | Points: 40 | Views : 242
<script>
  $(document).ready(function () {
var formatedDateTime = FormatDateTime();
alert(formatedDateTime);
})


 function  FormatDateTime() {
var todayDate = new Date();
var day = todayDate.getDate().toString();
day = day.length > 1 ? day : '0' + day;
var month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var format = "AM";
var hour = todayDate.getHours();
var min = todayDate.getMinutes();
if (hour > 11) { format = "PM"; }
if (hour > 12) { hour = hour - 12; }
if (hour == 0) { hour = 12; }
if (min < 10) { min = "0" + min; }
return month[todayDate.getMonth()] + " " + day + " , " + todayDate.getFullYear() + " " + hour + ":" + min + " " + format;
}

</script>


Out put :
Mar 15, 2016 12:56 PM

Comments or Responses

Login to post response