The next function should do what you want. It parses the string to create a date object using UTC values, then adjusts the UTC time to go to IST (+0530), and then returns a formatted string with equivalent IST values.
// Expects string in format: Fri Feb 13 2015 10:37:00 GMT+0000 // Assumes is UTC // Returns values in IST function parseAndFormat(s) { // Helper function z(n){return (n<10? "0":'') + n;} // Split into parts var b = s.split(/[ :]/); var m = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] var days = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']; // Create a date based on UTC values var d = new Date(Date.UTC(b[3], m.indexOf(b[1]), b[2], b[4], b[5], b[6])); // Add 5 hours 30 minutes to the UTC time -> IST d.setUTCHours(d.getUTCHours() + 5, d.getUTCMinutes() + 30); // Format the hours for am/pm var hr = d.getUTCHours(); var ap = hr > 11? 'PM' : 'AM'; hr = hr%12 || 12; // Format the output based on the adjusted UTC time var dt = days[d.getUTCDay()] + ' ' + m[d.getUTCMonth()] + ' ' + d.getUTCDate() + ' ' + d.getUTCFullYear() + ' ' + z(hr) + ':' + z(d.getUTCMinutes()) + ':' + z(d.getUTCSeconds()) + ' ' + ap; return dt; } console.log(parseAndFormat('Fri Feb 13 2015 10:37:00 GMT+0000')) // Fri Feb 13 2015 04:07:00 PM console.log(parseAndFormat('Fri Feb 13 2015 20:37:00 GMT+0000')) // Sat Feb 14 2015 02:07:00 AM
This method will work with local values, except when daylight saving time interferes. Please note that this is always an IST; it will not regulate daylight saving time observed in the places where it is used.
Edit
Fixed 12 hour conversion.
source share