mardi 20 juin 2017

Ruby: Datetime to UTC conversion

I am trying to convert the below date and time combination to UTC

from_date: "2017-06-19",from_time: "14:00" to_date: "2017-06-19", to_time: "23:00" Timezone: EDT

I am using below piece of code for conversion

Date.parse(dt).to_datetime + Time.parse(t).utc.seconds_since_midnight.seconds

And it gives the wrong date value for the to_date & to_time combination.

Output:

Date.parse(from_date).to_datetime + 
Time.parse(from_time).utc.seconds_since_midnight.seconds
 => **Mon, 19 Jun 2017 18:00:00 +0000**

Date.parse(to_date).to_datetime + Time.parse(to_time).utc.seconds_since_midnight.seconds
 => **Mon, 19 Jun 2017 03:00:00 +0000**

Above conversion should give "Tue, 20 Jun 2017 03:00:00 +0000" instead.

Aucun commentaire:

Enregistrer un commentaire