Search code examples
pythonjupyter-notebookjupyterlocale

configure Jupyter date format in metadata display, e.g. last checkpoint date


On top of my notebook I currently have “Last Checkpoint: 01/25/2022 (autosaved)” displayed. I would like this in a civilised readable different format. However I can’t find the option to change this.

The only mentions of date in the template config file (generated with jupyter notebook --generate-config) are:

## The date format used by logging formatters for %(asctime)s
#  Default: '%Y-%m-%d %H:%M:%S'
# c.Application.log_datefmt = '%Y-%m-%d %H:%M:%S'

## The date format used by logging formatters for %(asctime)s
#  See also: Application.log_datefmt
# c.JupyterApp.log_datefmt = '%Y-%m-%d %H:%M:%S'

## The date format used by logging formatters for %(asctime)s
#  See also: Application.log_datefmt
# c.NotebookApp.log_datefmt = '%Y-%m-%d %H:%M:%S'

All of those seem to refer to the logging and not to the displayed date. The config file contains no mention of locale or language. None of the environment variables I’ve tried have had any effect (including LANG, LC_ALL, LC_TIME, etc.), though they do affect python’s locale.getdefaultlocale().

This is the output of jupyter --version for what it’s worth:

jupyter  --version
Selected Jupyter core packages...
IPython          : 8.0.1
ipykernel        : 6.7.0
ipywidgets       : 7.6.5
jupyter_client   : 7.1.1
jupyter_core     : 4.9.1
jupyter_server   : not installed
jupyterlab       : not installed
nbclient         : 0.5.10
nbconvert        : 6.4.0
nbformat         : 5.1.3
notebook         : 6.4.6
qtconsole        : 5.2.2
traitlets        : 5.1.1

Solution

    • Right now when running jupyter notebook I do see dates in YYYY-DD-MM format, such as Last Checkpoint: 01/13/2022 (autosaved)
    • You can update this by changing your browser settings to "English (United Kingdom)" instead of American English (See instructions here)

    Some tips - how did I figure this out?

    1. Go to the GitHub for jupyter notebook - https://github.com/jupyter/notebook
    2. Search the repository for "Last Checkpoint:"
    3. We can find the relevant code here
    4. We can see this uses var chkd = moment(this._checkpoint_date); ...; chkd.calendar();, meaning this is formatted in the browser using the MomentJS library
    5. From the docs we can see that the display format is configured using moment.locale(...) - so we can search for this snippet in the code. We can see it here - moment.locale(_uiLang())
    6. Looking at _uiLang we can see it's just a wrapper around the browser language preference (source) - _uiLang = function() { return navigator.language.toLowerCase(); }
    7. I checked the localization files for MomentJS and we can see that British English does have the "correct" date format specified (source)