22

Is there any way to change Gmail date format to ISO 8601 (i.e., yyyy-mm-dd)?

Instead of :

enter image description here

0
9

I 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:

dates

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);
        }
      }
    }
  }
}
2
  • Note that you also need to set Gmail Language to "English (US)" in the Settings/General menu for this version of the script to work (as of today 2017-10-25). It will not work with "English (UK)". – wip Oct 24 '17 at 15:38
  • Why not edit the answer to put this in the main body where it can't be missed unlike in the comments? – Darryn Brisdaz Jun 23 '20 at 13:43
10

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.

1
  • As of the mid-2018 UI change, for number-only dates we now have m/d/yy in English (US), dd/mm/yyyy in English (UK) and Français, and yy-mm-dd in Français (Canada). These are indeed not ISO 8601. – Mathieu K. Nov 5 '18 at 14:19
1

Original script by: user79865

  1. Replaced @match with @include for better compatibility with Opera + Violentmonkey.
  2. Increased interval to fully adequately 1 second.
  3. Fixed display of time from 12 to 24 hour but kept the AM/PM for diplomatic reasons :)

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

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.

0

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

        }
    }

})();
0

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);
})();
2
  • Welcome. Please add a brief description or at least a reference to guide readers that are new to UserScript's (answer posters should assume that their answer will only have the question as context) – Rubén Mar 2 '20 at 23:52
  • Yes. You are right. Sorry. I got too exited that my script worked as expected. I just edited my response. – LovelyHanibal Mar 3 '20 at 19:50
-2

Try Canadian French instead of European French...

1
  • For number-only dates, as of the mid-2018 UI change, Français gives dd/mm/yyyy and Français (Canada) gives yy-mm-dd. Neither of these are ISO 8601, both are ambiguous, and the latter yields such ugly and mysterious constructions as 08-08-19 and 13-03-10. – Mathieu K. Nov 5 '18 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.