A simple function to format date in MM-DD-YYY hh:mm AM/PM format.
Usage : DateFormatter(Datevalue)
// Function that formats date
function DateFormatter(dateValue) {
var newDate = new Date(dateValue);
var sMonth = AdjustDate(newDate.getMonth() + 1);
var sDay = AdjustDate(newDate.getDate());
var sYear = newDate.getFullYear();
var sHour = newDate.getHours();
var sMinute = AdjustDate(newDate.getMinutes());
var sAMPM = "AM";
var iHourCheck = parseInt(sHour);
if (iHourCheck > 12) {
sAMPM = "PM";
sHour = iHourCheck - 12;
}
else if (iHourCheck === 0) {
sHour = "12";
}
sHour = AdjustDate(sHour);
return sMonth + "-" + sDay + "-" + sYear + " " + sHour + ":" + sMinute + " " + sAMPM;
}
//function that pads the values
function AdjustDate(value) {
return (value < 10) ? "0" + value : value;
}
// Code ends here
SharePoint all the way !!!
Usage : DateFormatter(Datevalue)
// Function that formats date
function DateFormatter(dateValue) {
var newDate = new Date(dateValue);
var sMonth = AdjustDate(newDate.getMonth() + 1);
var sDay = AdjustDate(newDate.getDate());
var sYear = newDate.getFullYear();
var sHour = newDate.getHours();
var sMinute = AdjustDate(newDate.getMinutes());
var sAMPM = "AM";
var iHourCheck = parseInt(sHour);
if (iHourCheck > 12) {
sAMPM = "PM";
sHour = iHourCheck - 12;
}
else if (iHourCheck === 0) {
sHour = "12";
}
sHour = AdjustDate(sHour);
return sMonth + "-" + sDay + "-" + sYear + " " + sHour + ":" + sMinute + " " + sAMPM;
}
//function that pads the values
function AdjustDate(value) {
return (value < 10) ? "0" + value : value;
}
// Code ends here
SharePoint all the way !!!
No comments:
Post a Comment