mckamey / countdownjs

A simple JavaScript API for producing an accurate, intuitive description of the timespan between two Date instances.
http://countdownjs.org
MIT License
496 stars 95 forks source link

How to Set a Countdown in Node.js with time zone? #26

Closed saeedhei closed 7 years ago

saeedhei commented 7 years ago

How to Set a Countdown in Node.js with time zone?

I need: begin at noon Eastern Standard Time on Wednesday November 22, 2017

today is 2017.11.01 and I used this code for checking tommorrow

const countdown = require('countdown');
var aaa = countdown( new Date(2017, 11, 2) ).toString();
console.log(aaa)

But my Output is: 1 month, 19 hours, 21 minutes and 11 seconds That Output is incorrect maybe because I'm in uae Now

mckamey commented 7 years ago

new Date(2017, 11, 2) => 2017-12-02

saeedhei commented 7 years ago

I'm Getting Syntax Error Can you edit my Example please and write full code and set to tommorow I mean today is 01.11.2017 and tommorow is 02.11.2017 ///////////////////////////////// var aaa = countdown(new Date(2017-11-2)).toString(); output 47 years, 10 months, 2 hours, 42 minutes and 31 seconds ///////////////////////////////// var aaa = countdown(new Date(2018, 11, 1), null, countdown.DAYS) console.log(aaa) days: 395 why 395?

mckamey commented 7 years ago

Months are zero based in the Date constructor. So:

const countdown = require('countdown'); var aaa = countdown( new Date(2017, 10, 2) ).toString(); console.log(aaa)

saeedhei commented 7 years ago

And for example I have a meet with my 2 friends in tommorow in my local time zone, And I set countdown for 24 hours later, but if someone be ahead of my local zone and someone behind of my local zone, then how should I solve this problem?

mckamey commented 7 years ago

Unfortunately, time zones are poorly supported in JavaScript. You basically can either work in UTC or the viewer’s browser local time zone. Not much else exists.

The countdown.js readme has a callout box that discusses time zones and how they relate to this.

The short answer is if you are talking about a specific point in time, use the milliseconds constructor to establish specific point in UTC time. If you are talking about a relative date (example New Year’s Day when the year changes), then specify with new Date(yyyy, M, d, H, m, s).

saeedhei commented 7 years ago

Thank you