I just coded this formatter to format timestamps in javascript (I tied it to underscore for convenience), any remark?
_.toDate = function(epoch, format, locale) {
var date = new Date(epoch),
format = format || 'dd/mm/YY',
locale = locale || 'en'
dow = {};
dow.en = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
];
var formatted = format
.replace('D', dow[locale][date.getDay()])
.replace('dd', ("0" + date.getDate()).slice(-2))
.replace('mm', ("0" + (date.getMonth() + 1)).slice(-2))
.replace('yyyy', date.getFullYear())
.replace('yy', (''+date.getFullYear()).slice(-2))
.replace('hh', date.getHours())
.replace('mn', date.getMinutes());
return formatted;
}
usage
_.toDate($.now(), "dd-mm-yy at hh:mn");
// Will output:
"27-03-13 at 17:20"