Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Last Modified Timestamp Format #202

Open
Gosokan opened this issue Jul 31, 2024 · 3 comments
Open

Change Last Modified Timestamp Format #202

Gosokan opened this issue Jul 31, 2024 · 3 comments

Comments

@Gosokan
Copy link

Gosokan commented Jul 31, 2024

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?

@misterunknown
Copy link
Owner

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.

@Gosokan
Copy link
Author

Gosokan commented Jul 31, 2024

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

@misterunknown
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants