UTC Time to local Time

by Pratik Bhoir

JavaScript

var str = '27/11/2014 1:01:06 PM';

function localize(t) {
    if (new Date(t) == 'Invalid Date') {
        var temp = t.split(' ');
        t = temp[0].split('/')[1] + '/' + temp[0].split('/')[0] + '/' + temp[0].split('/')[2] + ' ' + temp[1] + ' ' + temp[2];
    }
    var date = new Date(t + ' UTC');
    return date.getDate() + '/' + date.getMonth() + '/' + date.getFullYear() + ' ' + date.toLocaleTimeString();
    //return date.toLocaleString();
}

//alert(localize(str));
console.log(localize(str));