Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
How to change timestamp in javascript

I have that thing written in JS that put a timestamp on a sensor data to store it in a database. My problem is : The timestamp is early 2 hours.

So I would like to know how to add two hours in the script so that it write the good timestamp in the database.

Thanks !

var sqliteTimeStamp = Math.round(Date.now() / 1000); //converting to seconds instead of milliseconds epoch
var theDevice = "growtent";
var theSensor = "t01";
var d = new Date();
var epoch = d.getTime();

var theSQL = "INSERT INTO sensor_data (device,sensor,value,epoch) VALUES "
theSQL = theSQL + "('" + theDevice + "', '" + theSensor + "', '" + msg.payload + "', " + epoch +");";
msg.topic = theSQL;

// Update the status with current timestamp
var now = new Date();
var yyyy = now.getFullYear();
var mm = now.getMonth() < 9 ? "0" + (now.getMonth() + 1) : (now.getMonth() + 1); // getMonth() is zero-based
var dd = now.getDay() < 10 ? "0" + now.getDate() : now.getDate();
var hh = (now.getHours() +2) < 10 ? "0" + now.getHours(): now.getHours();
var mmm = now.getMinutes() < 10 ? "0" + now.getMinutes() : now.getMinutes();
var ss = now.getSeconds() < 10 ? "0" + now.getSeconds() : now.getSeconds();
node.status({ fill: "blue", shape: "ring", text: "Last update: " + dd + "." + mm + "." + yyyy + " " + hh + ":" + mmm + ":" + ss });

return msg;
about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda