Monday, August 8, 2016

JavaScript : Format Data to MM-DD-YYY hh:mm AM/PM

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 !!!

No comments:

Post a Comment

Rename a Web Application in Sharepoint : A solution using powershell

Here is a small script that will enable you all to change a SharePoint Web Application name . We can use the following SharePoint Pow...