jeudi 15 décembre 2016

Change the value of hash

I have a array of hash

response = [{"id"=>"008CFA1213EA1479500703798", "updated_at"=>"2016-11-18T20:27:03Z"}, {"id"=>"F452144578701479479453499", "updated_at"=>"2016-11-18T14:54:51Z"}] 

Desired Output

 desired_response = [{"id"=>"008CFA1213EA1479500703798", "updated_at"=>Fri, 18 Nov 2016 20:27:03 UTC +00:00}, {"id"=>"F452144578701479479453499", "updated_at"=>Fri, 18 Nov 2016 14:54:51 UTC +00:00}]

What I have do so far,

response.map {|x| x["updated_at"]}
["2016-11-18T20:27:03Z", "2016-11-18T14:54:51Z"]

response.map {|x| x["updated_at"]}.map {|x| DateTime.strptime(x).in_time_zone} 
[Fri, 18 Nov 2016 20:27:03 UTC +00:00, Fri, 18 Nov 2016 14:54:51 UTC +00:00]

I got the updated_at desired format but how to put it in response updated_at value or is there a better way to do this? Thanks

Aucun commentaire:

Enregistrer un commentaire