how to format date & time in javascript

how do i truncate the 'GMT+0100 (West Africa Standard Time)' part from my
new Date
new Date
? i know of the
get functions
get functions
, but i want the month to stay formatted as text and not numbers? how do i achieve this, please?
4 Replies
StefanH
StefanH2y ago
Date.prototype.toLocaleDateString() - JavaScript | MDN
The toLocaleDateString() method returns a string with a language-sensitive representation of the date portion of the specified date in the user agent's timezone. In implementations with Intl.DateTimeFormat API support, this method simply calls Intl.DateTimeFormat.
dys 🐙
dys 🐙2y ago
When I just want the date (not time) for a Date, I'll do new Date().toISOString().split('T')[0]. Could you split on ' '? (Or the toLocaleString is probably better, but more complex to figure out.)
StefanH
StefanH2y ago
This is probably a better idea than splitting that string https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString Often i find it easier to just use getHour(), getMinute(), getDay() etc and concatenate the date or time string myself if i want a very specific format
winniffy
winniffy2y ago
thanks, that's helpful thank you
Want results from more Discord servers?
Add your server