ifm icon indicating copy to clipboard operation
ifm copied to clipboard

Change Last Modified Timestamp Format

Open Gosokan opened this issue 1 year ago • 3 comments

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?

Gosokan avatar Jul 31 '24 06:07 Gosokan

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.

misterunknown avatar Jul 31 '24 11:07 misterunknown

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();
	};

Gosokan avatar Jul 31 '24 15:07 Gosokan

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.

misterunknown avatar Aug 01 '24 00:08 misterunknown