1

I have outputted a date type from a list of mine like so

while (listItemEnumerator.moveNext()) {

        var oListItem = listItemEnumerator.get_current();

        upStartDate.push(oListItem.get_item('EventDate'));      

}

and outputted it onto my page like so :

    for (i=0; i<upStartDate.length;i++){

test += upStartDate[i]+'</br>';
}

document.getElementById("addNextEventHere").innerHTML = test;

but the date comes out like Wed Jul 23 01:00:00 UTC+0100 2014 is there anyway I can format it so it is just the date so 23rd July 2014

1

1 Answer 1

1
var d = new Date("Wed Jul 23 01:00:00 UTC+0100 2014");

getFormattedDateWithOrdinal = function (date) {
    var d = new Date(date);
    var curr_date = d.getDate();
    var months = new Array("January", "February", "March","April", "May", "June", "July", "August", "September", "October", "November", "December");

    var ord = "";

    if (curr_date == 3 || curr_date == 23) {
        ord = "rd";
    }
    else if (curr_date == 1 || curr_date == 21 || curr_date == 31) {
        ord = "st";
    }
    else if (curr_date == 2 || curr_date == 22) {
        ord = "nd";
    }
    else {
        ord = "th";
    }

    return (curr_date + ord + " " + months[d.getMonth()] + " " + d.getFullYear());
};

console.log(getFormattedDateWithOrdinal(d));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.