Inspired question on How to format a JavaScript date
I have a date object in JavaScript and I want to print to the console in the following format: "14-Feb-2017". How can I do it?
This is the code I have:
var fecha = new Date();
console.log(fecha);
Use
toLocaleDateString
withes
as local andreplace
with regular expressions to make the fine adjustments since using onlytoLocaleDateString
the result would be14 feb. 2017
Example:
I add this answer for users who prefer to use the moment.js library , very popular when handling dates.
The details of the output format can be seen here
With information from here :