2

I am used to XFCE in various distributions, but thought I would try Ubuntu with GNOME for a change and to understand why so many people use it.

Frustratingly, I cannot find out how to change the date and time formatting to my preference. This is extremely simple in XFCE, but apparently not so much in Ubuntu with GNOME. In XFCE my time and date settings would be %A %d %B %Y %H:%M:%S (%Z), which would yield Monday 05 February 2024 13:13:43 (GMT). There are very limited options in the settings menu but my preferred formatting is not offered.

Is there a way to load this in the latest version of Ubuntu with GNOME (23.10)? Google searches only seem to offer the limited settings options.

1 Answers1

2

I made an extension that is compatible with Gnome Shell 45 on Ubuntu 23.10:

  1. Paste the following into ~/.local/share/gnome-shell/extensions/customDateTimeFormatting_1502527_1004020@askubuntu.com/metadata.json:

    {
        "uuid": "customDateTimeFormatting_1502527_1004020@askubuntu.com",
        "name": "Wall clock custom datetime formatter",
        "description": "Changes the wall clock date and time formatting to your preference",
        "shell-version": [ "45" ],
        "url": "https://askubuntu.com/q/1502527/1004020"
    }
    
  2. Paste the following into ~/.local/share/gnome-shell/extensions/customDateTimeFormatting_1502527_1004020@askubuntu.com/extension.js

    import GLib from 'gi://GLib';
    import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
    import {panel} from 'resource:///org/gnome/shell/ui/main.js';
    

    export default class CustomDateTimeFormattingExtension extends Extension { enable() { const { _clock, _clockDisplay } = panel.statusArea.dateMenu; _clock.force_seconds = true; // Update every minute -> update every second _clock.connectObject('notify::clock', () => { // This runs after the original code, // so we can just overwrite the original text. _clockDisplay.set_text( // Change the string on the new line according to your preferences: GLib.DateTime.new_now_local().format('%A %d %B %Y %H:%M:%S (%Z)') // No semicolon should be placed here ); }, this); }

    disable() {
        const { _clock } = panel.statusArea.dateMenu;
        _clock.disconnectObject(this);
        _clock.force_seconds = false;
    }
    

    }

  3. Relog

  4. Run gnome-extensions enable customDateTimeFormatting_1502527_1004020@askubuntu.com

    new date format preview

It does not have the preferences feature of the Panel Date Format extension (currently stuck on gnome-shell 42 on Ubuntu ≤ 22.04), owing to my goal of simplicity. If you want to change the format, you can just edit the extension.js and relog. My extension should be enough to solve this question. If you need more features, you can either comment, or wait for the Panel Date Format extension to get updated.

muru
  • 207,228
Daniel T
  • 5,339