Given that you already have text, you can just manipulate the text.
var dates = [{"date_play":"2016-08-22 00:00:00"},{"date_play":"2016-08-23 00:00:00"},{"date_play":"2016-08-24 00:00:00"}];
var newDates = [];
$.each(dates,function(i,obj){
newDates.push(obj['date_play'].replace(/(\d{4})-(\d\d)-(\d\d).*$/,'$2-$3-$1'));
});
console.log(newDates);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Or:
var dates = [{"date_play":"2016-08-22 00:00:00"},{"date_play":"2016-08-23 00:00:00"},{"date_play":"2016-08-24 00:00:00"}];
var newDates = [];
dates.forEach(function(obj){
newDates.push(obj['date_play'].replace(/(\d{4})-(\d\d)-(\d\d).*$/,'$2-$3-$1'));
});
console.log(newDates);
Or:
var dates = [{"date_play":"2016-08-22 00:00:00"},{"date_play":"2016-08-23 00:00:00"},{"date_play":"2016-08-24 00:00:00"}];
var newDates = dates.map(function(obj){
return obj['date_play'].replace(/(\d{4})-(\d\d)-(\d\d).*$/,'$2-$3-$1');
});
console.log(newDates);
Or:
var dates = [{"date_play":"2016-08-22 00:00:00"},{"date_play":"2016-08-23 00:00:00"},{"date_play":"2016-08-24 00:00:00"}];
var newDates = dates.map(function(obj){
var tmp = obj['date_play'].split(/[- ]/,3);
return tmp[1] + '-' + tmp[2] + '-' + tmp[0];
});
console.log(newDates);
Explaining the replace() regular expression:
The replace(), in this case, is being used with a RegExp (regular expression) which uses three capture groups to briefly hold the month, day and year, and then replace the string with just the contents of the capture groups separated by - characters, but in a different order (month-day-year).
replace(/(\d{4})-(\d\d)-(\d\d).*$/,'$2-$3-$1')
│ ││ ││ │ │ ││ │ │ │││││ │ │ └───Replace with capture group #1 (year)
│ │┕┯┙│ │ │ ││ │ │ │││││ │ └──────Replace with capture group #3 (day)
│ │ │ │ │ │ ││ │ │ │││││ └─────────Replace with capture group #2 (month)
│ │ │ │ │ │ ││ │ │ ││││└────────────── $ = The end of the string (not really needed here)
│ │ │ │ │ │ ││ │ │ │││└─────────────── * = Repeat the previous character, or group, 0 up to as many times as possible ( .* matches the rest of the string)
│ │ │ │ │ │ ││ │ │ ││└──────────────── . = Any character
│ │ │ │ │ │ ││ │ │ │└───────────────── ) = End capture group #3 (which is 2 digits, the day)
│ │ │ │ │ │ ││ │ │ └────────────────── \d = A digit
│ │ │ │ │ │ ││ │ └──────────────────── \d = A digit
│ │ │ │ │ │ ││ └────────────────────── ( = Begin capture group #3
│ │ │ │ │ │ │└──────────────────────── ) = End capture group #2 (which is 2 digits, the month)
│ │ │ │ │ │ └───────────────────────── \d = A digit
│ │ │ │ │ └─────────────────────────── \d = A digit
│ │ │ │ └───────────────────────────── ( = Begin capture group #3
│ │ │ └─────────────────────────────── ) = End capture group #1 (which is 4 digits, the year)
│ │ └───────────────────────────────── {4} = Repeat the previous character, or group, exactly 4 times (4 digits, the year)
│ └─────────────────────────────────── \d = A digit
└───────────────────────────────────── ( = Begin capture group #1
All of the '-' characters are just '-' characters: part of the old string, or part
of the replacement.