You can use the methods of the Date
object JavaScript to do this. See:
var data = {
date: "2014-06-16 21:56:29"
};
var date = new Date(data.date),
day = date.getDate(),
month = date.getMonth(),
year = date.getFullYear(),
monthNames = ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'];
alert(day + ' de ' + monthNames[date.getMonth()] + ' de ' + year);
To test, I have prepared this jsFiddle for you.
Explanation
day
, month
and year
are variables where the numbers of the dates that you use will be stored - these numbers are taken by their% methods getDate()
, getMonth()
and getFullYear()
that JavaScript itself comes.
In alert()
, I'm using monthNames[date.getMonth()]
because date.getMonth()
returns the months in American format and it follows the indexing flow of the names of the months used in the monthNames
vector, so they both coincide.