Over a million developers have joined DZone.

Create A Datetime String From UK Formatted Date String And Timestamp

·
// Creates a date object from a date string and a time string. Has to convert into an american format so that the date object holds the correct date


function CreateFullDate(dateStr, TimeStr) {
    // Convert into a uk date object
    var formatUK = FormatUkDate(dateStr);
    // Next take the uk date object and convert into an american date string!
    var formatUS = formatUK.format("MM/dd/yyyy");
    // Create a new date object from the american date and time
    return new Date(formatUS + " " + TimeStr);
}


function FormatUkDate(dateStr) { 
    dateStr = dateStr.split("/");
    return new Date(dateStr[2], dateStr[1] - 1, dateStr[0]);
}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}