No matter how many times I need do it I always end up in docs or stackoverflow.

And let's be honest date formatting in js is ... well not that simple.

This snippet is as straightforward as possible, but gets job done. I usually use it for folder naming or other minor stuff, where getting separate lib like Moment.js just for that seems like overkill.

const t = new Date();
const formattedDate =
t.getDate() +
'-' +
t.getMonth() +
'-' +
t.getFullYear().toString().replace(/^\d{2}/, '') +
'\s' +
t.getHours() +
':' +
t.getMinutes(); // output '18-11-19 17:37'

Of course if you want other date than "now" you need to pass it in the Date constructor.

But if you are in need of more advanced, flexible and dependency-free ...

package.json

{
// ...
"dependencies": {},
//..
}

library for handling time in js date-fns should do just perfect.