samedi 19 octobre 2019

Date conversion in UTC

I am working ruby on rails. In that I have a doubt in date conversion from current timezone to UTC.

The date conversion function is

function date_conversion(date){
    out = moment(date, "DD/MM/YYYY").format('YYYY-MM-DD')
    var utc_time = moment.tz(out, zone).tz('UTC').format();
    return utc_time;
}

Here params date let as "12/10/2019" which is in string format and let the zone is ""Asia/Kolkata".

After executing the date_conversion function the values are

   out = moment(date, "DD/MM/YYYY").format('YYYY-MM-DD') 

The output of out = "2019-10-12"

   var utc_time = moment.tz(out, zone).format();

The value of utc_time is 2019-10-12T00:00:00+05:30. There is no problem while using above. But when i am trying to convert to UTC as below

    var utc_time = moment.tz(out, zone).tz("UTC").format();

I got 2019-10-11T18:30:00Z. In this situation I need of date in UTC but that date not to be changed. Please tell anybody some idea for this

Aucun commentaire:

Enregistrer un commentaire