/    Sign up×
Community /Pin to ProfileBookmark

Javascript Date Objects

What’s going wrong here, the first code works. The second one doesn’t. 

I have two dates and I can get the time difference between them 

const countToDate = new Date(“2024-02-21”)
const currentDate = new Date()
console.log(Math.ceil((countToDate – currentDate) / 1000))

This works and gives me the seconds between them.

When I create dates and covert the timezone, it fails. Here’s some code

const VenueDate = new Date();
var dateFormat = newIntl.DateTimeFormat(“en-US”, {timeZone:”Europe/Paris”});
const formatted = dateFormat.format(VenueDate);  

const startDateTime = new Date(‘2024-02-15 09:00:00.000000’)
const formattedStart = dateFormat.format(startDateTime );

console.log(Math.ceil((formatted – formattedStart ) / 1000))

Any help please

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@wbportFeb 10.2024 — Have you first hit F12 in your browser before running this code?

Review everything about Date constructors and methods. Also, you might want to use this format to set a date:
Mmm d[d], yyyy [hh:mm[:ss.sss]] [TZN]    E.g., Jan 1, 2008 14:00 GMT

Good luck!
×

Success!

Help @kiwis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...