Is there any way to change Gmail date format to ISO 8601 (i.e., yyyy-mm-dd)?
Instead of :
Web Applications Stack Exchange is a question and answer site for power users of web applications. It only takes a minute to sign up.
Sign up to join this communityI don't see a built-in way to switch to ISO format, but I wrote a userscript for this. Tested in Chrome with Tampermonkey. If Tampermonkey is installed, clicking Raw button in Github should prompt for script installation.
You did not ask for time format to be changed, so I kept it as is for today's emails:
Including script here for completeness. (added wildcards to URL)
// ==UserScript==
// @name ISO date format in Gmail
// @namespace https://github.com/normalhuman/
// @version 16.2.1
// @description Change Gmail date format to ISO 8601, per http://webapps.stackexchange.com/q/89499
// @author Normal Human
// @match http*://mail.google.com/mail/u/0/*
// @grant none
// @run-at document-idle
// ==/UserScript==
/* jshint -W097 */
'use strict';
window.setInterval(toISO, 500);
function toISO() {
var rows = document.getElementsByTagName('tr');
for (var i = 0; i < rows.length; i++) {
var rowElements = rows[i].children;
if (rowElements.length == 8) {
var timestamp = rowElements[7].firstElementChild;
if (!/:/.test(timestamp.textContent)) {
var parts = timestamp.title.split(/, | | at /);
if (parts.length == 7) {
var month = 1 + ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'].indexOf(parts[1]);
timestamp.textContent = parts[3] + '-' + ('0' + month).slice(-2) + '-' + ('0' + parts[2]).slice(-2);
}
}
}
}
}
This is controlled exclusively through the language setting.
With my language set to English (United States), dates in the conversation list are in the form Mmm d, with dates for last year and earlier in the form mm/dd/yyyy.
When changed to English (United Kingdom), the forms change to d Mmm and dd/mm/yyyy respectively.
There no other options for English in Gmail. When changed to French, it follows basically the same style as UK English (but obviously in French, which I don't speak or read).
There is no other setting for localization within Gmail, and no way to choose date format independent of language. It would seem your only choice at this time is to use something like the userscript suggested by they-of-the-ever-changing-name.
Someone made an extension to do this. You do have to set a custom format, but for ISO 8601 it's just the typical "YYYY-MM-DD HH:mm" used in most other date format strings.
I should also mention that this will change all dates, including recent dates, such as when the day of the week, "Yesterday", or just the time would normally be displayed.
Original script by: user79865
Working script below:
// ==UserScript==
// @name ISO date format in Gmail
// @namespace https://github.com/normalhuman/
// @version 16.2.2
// @description Change Gmail date format to ISO 8601, per https://webapps.stackexchange.com/q/89499
// @author Normal Human
// @include http*://mail.google.com/mail/u/0/*
// @grant none
// @run-at document-idle
// ==/UserScript==
/* jshint -W097 */
'use strict';
window.setInterval(toISO, 1000);
function toISO() {
var rows = document.getElementsByTagName('tr');
for (var i = 0; i < rows.length; i++) {
var rowElements = rows[i].children;
if (rowElements.length == 8) {
var timestamp = rowElements[7].firstElementChild;
var parts = timestamp.title.split(/, | | at /);
if (parts.length == 7) {
if (/:/.test(timestamp.textContent)) {
var time = parts[5].split(':');
time[0] = parseInt(time[0],10);
if (/[Aa][Mm]/.test(parts[6])) {
if (time[0] == 12) {
time[0] = 0;
}
}
if (/[Pp][Mm]/.test(parts[6])) {
time[0] = time[0] + 12;
if (time[0] == 24) {
time[0] = 0;
}
}
timestamp.textContent = ('0' + time[0]).slice(-2) + ':' + time[1] + ' (' + parts[6] + ')';
} else {
var month = 1 + ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'].indexOf(parts[1]);
timestamp.textContent = parts[3] + '-' + ('0' + month).slice(-2) + '-' + ('0' + parts[2]).slice(-2);
}
}
}
}
}
Few years have passed, Gmail still has the same problem, but non of the previous solutions is working, so here is my script which works at the moment (2020-03-02).
For those not familiar with userscript, you install an extension in Chrome — tampermonkey (long time ago it was called greasemonkey) —, and in its settings you write or paste Javascript code that will be injected in some websites.
// ==UserScript==
// @name Gmail with ISO Date
// @namespace http://peter-sobieraj.ca7.eu/
// @version 1.0
// @description Change Gmail date format to ISO 8601, per https://webapps.stackexchange.com/q/89499
// @author LovelyHanibal
// @match https://mail.google.com/mail/u/*
// @grant none
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
function toISO() {
var rows = document.getElementsByClassName('xW');
for (var i = 0; i < rows.length; i++) {
var d = new Date(rows[i].firstElementChild.title);
if( d != 'Invalid Date' ){
var x = rows[i].firstChild;
x.innerText = d.getFullYear() + '-' + ('0' + (d.getMonth()+1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2);
}
}
}
window.setInterval(toISO, 1000);
})();
UserScript
's (answer posters should assume that their answer will only have the question as context)
The 2 above script didn't work out-of-the-box for me, to so I rewrite them for my case (Firefox v57 + Tempermonkey and Gmail locale en-UK
).
// ==UserScript==
// @name ISO Date for Gmail
// @namespace http://rabin.io/
// @version 0.1
// @description Change Gmail date format to ISO 8601, per https://webapps.stackexchange.com/q/89499
// @author Rabin
// @match https://mail.google.com/mail/u/*
// @grant none
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
window.setInterval(toISO, 1000);
function toISO() {
var rows = document.getElementsByClassName('xW');
for (var i = 0; i < rows.length; i++) {
var timestamp = rows[i].firstElementChild.title.split(/, | | at /);
if (timestamp.length == 5) {
var d = new Date(timestamp[1] + " " + timestamp[0] + " " + timestamp[2] + " " + timestamp[4]);
var x = rows[i].firstChild;
//x.textContent = d.toISOString();
x.textContent = d.getFullYear() + '-' + ('0' + (d.getMonth()+1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2);
}
}
}
})();