ifm
ifm copied to clipboard
Change Last Modified Timestamp Format
Hello,
I want to ask, how to change last modified timestamp date formatting to Y/m/d H:i:s instead d/m/Y h:i?
At the moment the browser tries to detect your locale and formats the date accordingly. There is no way to adjust the date format manually. I might get around to implement it, but not this week.
I've found the answer, by modifying the following line:
/**
* Formats a date from an unix timestamp
*
* @param {integer} timestamp - UNIX timestamp
*/
this.formatDate = function( timestamp ) {
let d = new Date( timestamp * 1000 );
return d.toLocaleString(navigator.language || "en-US");
};
to
this.formatDate = function( timestamp ) {
let d = new Date( timestamp * 1000 );
const day = d.getDate().toString().padStart(2, '0');
const month = (d.getMonth() + 1).toString().padStart(2, '0');
const year = d.getFullYear();
const hours = d.getHours().toString().padStart(2, '0');
const minutes = d.getMinutes().toString().padStart(2, '0');
const seconds = d.getSeconds().toString().padStart(2, '0');
const formattedDate = `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`;
return formattedDate.toLocaleString();
};
Well, I'm glad if that works for you, but that is not really flexible tbh. Apparently javascript doesn't have a strftime compatible format function, so I guess it isn't that easy to write something configurable.