I have this function to print out dates or minutes/hours from tweets. It works fine but dates are in English. How can I change the months into e.g. Spanish? The date format is fixed – it comes from the Twitter API.
It looks like this:
var $time = "Fri May 04 20:33:17 +0000 2018";
function relative_time(time_value) {
// How can I apply these months to the function?
//var months = Array('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre');
var values = time_value.split(" ");
time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
var parsed_date = Date.parse(time_value);
var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
var shortdate = time_value.substr(4, 2) + " " + time_value.substr(0, 3);
delta = delta + (relative_to.getTimezoneOffset() * 60);
if (delta < 60) {
return '1m';
} else if (delta < 120) {
return '1m';
} else if (delta < (60 * 60)) {
return (parseInt(delta / 60)).toString() + 'm';
} else if (delta < (120 * 60)) {
return '1h';
} else if (delta < (24 * 60 * 60)) {
return (parseInt(delta / 3600)).toString() + 'h';
} else if (delta < (48 * 60 * 60)) {
//return '1 day';
return shortdate;
} else {
return shortdate;
}
}
Check out Fiddle here.
3
Answers
With moment.JS : viernes, 4 de mayo de 2018 22:33
Does this answer your question?