3

I'm making a Discord bot and want it to be able to say the time it was started, but when I use Date(); it returns with a completely different time than my computer's local time, which makes it really difficult to tell when it actually started.

The code I'm using :

var currentdate = new Date();
console.log(currentdate)

The time I'm getting:

2017-10-15T10:37:14.912Z
Ivar
  • 6,138
  • 12
  • 49
  • 61
kittrz
  • 81
  • 1
  • 3
  • 13

4 Answers4

4

You can try this:

var d = new Date();
console.log(d.toLocaleTimeString());
console.log(d.toLocaleString());
console.log(d.toLocaleDateString());
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
3

you can try following code

var currentdate = new Date(); 
var datetime = "Date Time: " + currentdate.getDate() + "/"
    + (currentdate.getMonth()+1)  + "/" 
    + currentdate.getFullYear() + " @ "  
    + currentdate.getHours() + ":"  
    + currentdate.getMinutes() + ":" 
    + currentdate.getSeconds();
console.log(datetime)

Click here for more information

Dhaval Pankhaniya
  • 1,996
  • 1
  • 15
  • 26
3

Consider using moment.js

It's a great module for time related stuff. If you're using a remote server chances are the time you're seeing is GMT+0.

With moment you can find your global time zone and add that as an offset when displaying the time. There are also handy features for controlling the display format.

For example to display in my time zone I just use

moment().utcOffset(-4).format("dddd, MMMM Do YYYY, h:mm:ss a"); // "Sunday, February 14th 2010, 3:25:50 pm"

https://momentjs.com/docs/#/manipulating/utc-offset/

Astrydax
  • 463
  • 3
  • 15
0

What am i using for displaying full date?

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

I use d in the area i want to set the date!

Koza Nostra
  • 195
  • 14