Search code examples
node.jsamazon-web-servicesaws-lambdaalexa-skills-kit

How to get the time zone


I am trying to get the time for my echo skill. I got the time, but it is in the wrong time zone. how do I make it to where the time adjusts to the time zone?

Here is my code:

var d = new Date(); 
var dateHour = d.getHours();
var dateMinutes = d.getMinutes();

var nonTime = dateHour + ":" + dateMinutes;
var dateTime = nonTime

var speechOutput = "This is a test " + today + ' ' + dateTime ;
this.emit(':tellWithCard', speechOutput, today); },

The time that I posted this is 10:16, here is what my log displays:

   "outputSpeech": {
  "type": "SSML",
  "ssml": "<speak> This is a test September 5, 2017 3:16 </speak>"

Solution

  • Momentjs is your friend. You can pass in your time zone and get the current time in that zone.

    https://momentjs.com/timezone/docs/

    All scripts run in UTC timezone. You need to specify the timezone of the user.