I capture a date in format yyy-mm-dd (2016-06-30)
and I want to give it a more friendly format for the user, I look for the following:
2016-06-30 = 6 de Junio del 2016
2016-06-30 = Junio (Mostrar el mes dada la fecha)
2016-06-30 = Jueves (Mostrar el día, suponiendo que el 06 sea Jueves).
This is the standard option, available in most browsers (all modern ones),
toLocaleDateString
An example.
Other that includes the day of the week:
If you look at the documentation noted above, there are different options to display all or just some of the parts in the formatted date.
Depending on the options you use, you can show only the day, or the month. Also you can, if you don't include the locale ("es-ES" - Spanish from Spain) leave it to use the user's locale. This is usually a good practice since the user has configured a preferred format and it is good to respect it.
Salu2
According to the documentation you can try the following:
Adjusted test code from the following source .
If you contemplate the idea of using only javascript, I recommend using the following code:
Code edited from Alejandro Ricotti's answer .
You could test in a simple way using momentjs
Don't forget to include the locals
Well, with JavaScript 'barely' you would have to create a
Array
with all the names of the months and 'map' them:For the days of the week you would have to do something similar.
Taking into account the answers, I have found the solution just as I needed it using the momentjs library :
For more information about formats using momentjs here
Thank you very much for your time and your help, it was very useful.