0

I would like to convert a date from my filter to UTC time and then to seconds keeping the UTC time / not the local time.

Examples:

new Date()  // Wed Aug 19 2020 15:28:09 GMT+0200 (Central European Summer Time)
moment.utc(new Date()).format()  // correctly outputs 2020-08-19T13:28:09Z - so -2h
moment.utc(new Date()).format('X')  // unix timestamp 1597843870 - 19/08/2020, 15:31:10 Summer Time returns time plus 2h - not what I want
moment.utc(new Date()).unix()  // again as above unix timestamp 1597843870 - 19/08/2020, 15:31:10 Summer Time returns time plus 2h - not what I want

So to summarize I need to convert the UTC formatted time to a number of seconds so it is (whenever converted with convertor the same number of seconds). Meaning this: moment.utc(new Date()).format() after conversion to seconds needs to be 1597843689

Is there any reasonable way how this could be done with a moment?

xyz83242
  • 629
  • 14
  • 27
  • Try the getTime method, `new Date().getTime()` – Kunal Mukherjee Aug 19 '20 at 13:48
  • 1
    You seem to be making this more complicated than it is. A date object already contains all the information and functionality that you need: `Math.floor(Date.now() / 1000)` – str Aug 19 '20 at 13:56

0 Answers0