3 ms·
Someone recently added moment to our project to parse some dates. More recently, I decided to use it to parse and format some dates somewhere else, and I immedi
by mcv 6y ago
Someone recently added moment to our project to parse some dates. More recently, I decided to use it to parse and format some dates somewhere else, and I immediately got flak for it.
This is, all I need moment for, is simple date.formatAs('DD-MM-YYYY') and date.parse(date, 'YYYY-MM-DD') stuff. moment is overkill for that, but js Date somehow doesn't do it. It would probably be quicker to write one myself than to find a library that does just that.
- bufferoverflow 6y agoThat's what Intl.DateTimeFormat is for. var options = { year: 'numeric', month: '2-digit', day: '2-digit'}; console.log(new Intl.DateTimeFormat('te-IN', options).format(new Date())); // outputs 16-09-2020
- mcv 6y agoNot as far as I can tell. It just formats it according to a locale, not according to a format string. SimpleDateFormat for javascript[0] looks more like what I need. Locales are exactly the thing I don't need. [0] https://github.com/noahcooper/SimpleDateFormatJS https://github.com/noahcooper/SimpleDateFormatJS
- bufferoverflow 6y agoWhy use a whole freaking library instead of just writing a one-line function?
- mcv 6y agoBecause I'd have to write a lot of variations of that one-line function to handle different date format variations from various systems.