After receiving a response from a service, the date returned is in GMT format. However, I need to convert this date to my local time and display it as 5-22-2016
. The problem arises when trying to change the time to match my local computer.
The response structure is as follows:
createdDate: "2016-04-22 16:48 PM GMT"
description: "File Upload Success"
fileGuid:"62e7250c-d5ed-41e2-b5b2-4600094d9a7c"
fileSize:"191429"
There are a total of 90 objects in my array, and I am attempting to use the _each
function to iterate through all key-value pairs:
_.each(data, function(value, key) {
console.log(key, value);
var strDateTime = value.createdDate;
var myDate = new Date(strDateTime);
data[key].createdDate = (myDate.toLocaleString()).split(',')[0];
console.log("data", data)
Despite this approach working for some created dates, there are instances where it returns an invalid result. Any suggestions on how to resolve this issue?