0

I'm using Date in JavaScript :

 getCurrentDateTime = () => {
    var d = new Date(),
      dformat =
        [
          d.getDate().padLeft(),
          (d.getMonth() + 1).padLeft(),
          d.getFullYear()
        ].join("/") +
        " " +
        [
          d.getHours().padLeft(),
          d.getMinutes().padLeft(),
          d.getSeconds().padLeft()
        ].join(":");

    return dformat;
  };

In my Mongoose Schema :

const mongoose = require("mongoose");
const LoggerSchema = new mongoose.Schema({
  // .. Some attributes 


  InsertDate: {
    type: Date,
    default: Date.now
  },
  InsertDateDetailed: {
    type: String
  }
});

module.exports = Logger = mongoose.model(
  "logger",
  LoggerSchema
);

And it's always 2 hours late :

enter image description here

Why ?

JAN
  • 21,236
  • 66
  • 181
  • 318
  • 4
    What timezone are you in? :) Did you specify UTC? – Icepickle Nov 18 '19 at 16:26
  • Can you make sure that your date isn't in UTC ? – Nicolas Nov 18 '19 at 16:26
  • @Icepickle : (GMT+2) – JAN Nov 18 '19 at 16:27
  • 1
    Where is it two hours late? `InsertDateDetailed` and `InsertDate` are the same... – Heretic Monkey Nov 18 '19 at 16:27
  • @HereticMonkey: The time in Israel right now is 6:28 PM , both are 2 hours late – JAN Nov 18 '19 at 16:29
  • Is your server configured with a different timezone? – Manuel Spigolon Nov 18 '19 at 16:31
  • Does this answer your question? [Convert UTC date time to local date time](https://stackoverflow.com/questions/6525538/convert-utc-date-time-to-local-date-time) – Icepickle Nov 18 '19 at 16:31
  • Might be good information to have in the question... And I would say the values are two hours behind, but that might just be a language thing. I'm not seeing where in your code the `getCurrentTime` function is associated with the Mongoose code. – Heretic Monkey Nov 18 '19 at 16:31
  • By default JavaScript Date objects are in UTC. https://stackoverflow.com/questions/15141762/how-to-initialize-a-javascript-date-to-a-particular-time-zone – BA_Webimax Nov 18 '19 at 16:34
  • @ManuelSpigolon: My server is `Heroku` , it runs the `NODE JS` code.You thing it might be configured without UTC ? – JAN Nov 18 '19 at 16:57
  • 1
    [They are UTC](https://stackoverflow.com/questions/33995194/what-timezone-is-heroku-server-using), if you want your TZ check the link how to update your instance – Manuel Spigolon Nov 18 '19 at 17:37
  • @ManuelSpigolon: Post at as an answer , thank you very much! – JAN Nov 18 '19 at 18:06
  • To check what your system is set to, view the output of `date.toString()`, which will include the default timezone and offset that the system is set to. It will produce a string like "Tue Nov 19 2019 10:16:35 GMT+1000 (AEST)". The plain *get\** methods return "local" values, i.e. based on the system timezone and offset. The *getUTC\** methods return UTC values, i.e. they ignore the host timezone and offset settings. – RobG Nov 19 '19 at 00:15
  • Possible duplicate of [What timezone is Heroku server using?](https://stackoverflow.com/questions/33995194/what-timezone-is-heroku-server-using) – Manuel Spigolon Nov 19 '19 at 07:39

0 Answers0