Unix TimeStamp Convert to +02: 00

2

I have the following date 1535440000 I am converting it in such a way to Timestamp:

recvTime: new Date(params.contextResponses[i].contextElement.attributes[j].metadatas[k].value * 1000).toISOString()

The problem is that I have to convert that date to +2 hours. In these moments I have:

"recvTime" : "2018-08-28T06:17:47.000Z"

I would need to check the time zone before the conversion. How can I do it to get a +2 in the hour?

The correct thing would be this: "recvTime" : "2018-08-28T08:17:47.000Z"

I've tried the Moment library, but I have not downloaded anything.

Thank you, best regards.

EDIT01

Code:

var data_inver = [];
     var asociar_inver = [];
     for (var i = 0; i < params.contextResponses.length; i++) {
       for (var j = 0; j < params.contextResponses[i].contextElement.attributes.length; j++) {
         for (var k = 0; k < params.contextResponses[i].contextElement.attributes[j].metadatas.length; k++) {
           var medidas_inver = {
              id_greenhouse : params.contextResponses[i].contextElement.id,
              attrName : params.contextResponses[i].contextElement.attributes[j].name.concat("-",params.contextResponses[i].contextElement.id),
              attrType: params.contextResponses[i].contextElement.attributes[j].type,
              attrValue: params.contextResponses[i].contextElement.attributes[j].value,
              recvTimeTs: params.contextResponses[i].contextElement.attributes[j].metadatas[k].value,
              recvTime: new Date(params.contextResponses[i].contextElement.attributes[j].metadatas[k].value * 1000).toISOString()
           };
           data_inver.push(medidas_inver);
           console.log('Mostramos las medidas:' + JSON.stringify(data_inver));
         }
       }
   }
    
asked by Manolait 24.09.2018 в 15:50
source

1 answer

0

you could only add this time to unix time

2*60*60*1000
(hora) * (minutos) * (segundos) * milisegundos(1000)

that would be 2 hours in milliseconds, just add that time to UNIX time and it should work.

in your code would be like this

recvTime: new Date(params.contextResponses[i].contextElement.attributes[j].metadatas[k].value * 1000).toISOString() + 2*60*60+1000

Greetings.

    
answered by 24.09.2018 в 16:06