Ramonkos Posted May 9, 2020 Share Posted May 9, 2020 Formatting dates seem to be not working in the examples of W3 schools. Any ideas why? https://www.w3schools.com/js/js_date_formats var d = new Date("2015-03-25"); results in:Wed Mar 25 2015 01:00:00 GMT+0100 (Central European Standard Time) Link to comment Share on other sites More sharing options...
Ingolme Posted May 10, 2020 Share Posted May 10, 2020 What is the expected result? Link to comment Share on other sites More sharing options...
ishan_shah Posted May 11, 2020 Share Posted May 11, 2020 I assume you want o/p like 2015-0325 only. So for that, You can pull out the parts of a DateTimeFormat one-by-one using DateTimeFormat#format, but note that when using this method, as of March 2020, there is a bug in the ECMAScript implementation when it comes to leading zeros on minutes and seconds . const d = new Date('2010-08-05') const ye = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(d) const mo = new Intl.DateTimeFormat('en', { month: 'short' }).format(d) const da = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(d) console.log(`${da}-${mo}-${ye}`) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now