/    Sign up×
Community /Pin to ProfileBookmark

Converting string to Datetime is showing Invalid Date error in Firefox browser

In my AngularJs application, I am getting the date in string format which I need to convert to datetime and show in a datepicker. It’s working in Chrome but in Firefox converting string to datetime is showing “Invalid Date” error. I have used below code

new Date(’02-11-2021 07:11 PM’)

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumFeb 10.2021 — In the docu at MDN you find several examles of creating a date object:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#examples

Your string doesn't match any of them. Use one of the formats they give.
Copy linkTweet thisAlerts:
@marksmith121Feb 12.2021 — function parseDate(input) {

let parts = input.split('-');

// new Date(year, month [, day [, hours[, minutes[, seconds[, ms]]]]])

return new Date(parts[0], parts[1]-1, parts[2]); // Note: months are 0-based

please solution from here.

https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results
×

Success!

Help @neo_mn 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.3,
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,
)...