DEV Community

Cover image for How to Customize Date Format Using Terminal on macOS (Bite-size Article)
koshirok096
koshirok096

Posted on

How to Customize Date Format Using Terminal on macOS (Bite-size Article)

Introduction

Note: This article is written for Mac users.

I recently updated macOS to the latest version, Sonoma. With this update, I found that the default date format was changed. Usually, I prefer to use DD/MMM/YY format for long years, and have used it for logging work and personal projects. However, with the new OS update, I could no longer use my preferred format.

Image description

Of course, it is very inconvenient to be able to input data manually but not be able to use keyboard shortcuts.

When the date format you use daily changes, it takes time to get used to it. In my case, I was accustomed to the format like, "16/Jun/2024", but it changed to "16/6/24" now, which I found harder to read. While the system preferences offer several date formats, none exactly matched the format I was using.

Searching on Google about this issue, I found that other Mac users were also looking for a solution in various forums. Although this is a minor change, it has impacted some users. Therefore, I wondered if it was possible to revert to the original format.

Fortunately, I found a solution, and in this article, I will introduce how to customize the date format using Terminal.

* Please note that the following steps involve customizing the system-wide settings domain. This could lead to unexpected behavior or issues. Please proceed at your own discretion and responsibility!

Image description

Changing Date Format Using Terminal

In macOS, you can customize the system-wide date format using Terminal. Here are the steps to change the date format to "DD/MMM/YY".

Step 1: Open Terminal

First, open Terminal. You can usually find Terminal in the "Utilities" folder within the "Applications" folder.

Step 2: Execute the Command to Change Date Format

Enter the following command in Terminal and execute it:

defaults write NSGlobalDomain AppleICUDateFormatStrings -dict-add 2 "dd/MMM/yy"
Enter fullscreen mode Exit fullscreen mode

Executing this command will apply the settings change.

Image description

Explanation of the Command

This command is used to change the default settings in macOS. Specifically, it adds a new date format to the setting domain called NSGlobalDomain. Here is a detailed explanation of each part of the command:

  • defaults write: This is the basic command to change macOS settings.
  • NSGlobalDomain: This indicates that the setting applies system-wide.
  • AppleICUDateFormatStrings: This is the key for customizing the date format.
  • -dict-add 2: This specifies that we are changing the "medium" date format. macOS categorizes date formats into several types. 1: Short format, 2: Medium format, 3: Long format and 4: Full format

  • "dd/MMM/yy": This part is the new date format. dd stands for day, MMM stands for the abbreviated month, and yy stands for the last two digits of the year.


By following these steps, you can customize your macOS date format to suit your preferences.

Tip: Date Format Types

In macOS, there are several preset date formats, each tailored for different purposes and display styles. These presets are categorized as follows:

a. Short Format (1):

A simple format typically represented with only numbers.
Example: 12/31/23

b. Medium Format (2):

Contains a bit more detail than the short format but remains relatively compact.
Example: 31/Dec/23
This format is suitable for everyday use and is commonly used in many calendar apps and system date displays.

c. Long Format (3):

Includes more detailed information with the full name of the month.
Example: December 31, 2023

d. Full Format (4):

The most detailed format, including additional information like the day of the week and time.
Example: Sunday, December 31, 2023 at 11:59:59 PM

-dict-add 2 means changing the "medium" format among the date formats. This format is widely used in many everyday applications and systems, and changing it can significantly affect the appearance of date displays.

Image description

Step 3: Restarting the System

By executing the above command, the settings should be applied. According to the resources I referred to, a restart may be required to enable the settings, although in my case, it worked without a restart.

Try using the shortcut command cmd + shift + 1 (default) to date-stamp in a text to check if the change has been made. Additionally, you can change to other formats according to your preference (e.g., DD/MM/YYYY).

If the date format has changed as desired, it means the operation was successful!

Tip: Risks and Disadvantages of Changing Date Formats

When changing date formats in macOS using the Terminal, there are several risks to consider. Although it is challenging to convey all potential issues, here are some key points to be aware of:

  • Application Dependency: Some applications may depend on a specific date format, which could lead to operational issues if the format is changed.
  • System-wide Impact: Changing the date format affects the entire system, potentially leading to unexpected behaviors or displays in the future.
  • Resetting After Updates: macOS updates may reset the settings, requiring you to reconfigure them.
  • Troubleshooting Challenges: Custom settings can complicate troubleshooting. If problems arise, Apple's official support or other support resources may not be able to respond appropriately.

Consider these points carefully before deciding to change the settings.

Image description

Conclusion

Even if the date format in macOS Sonoma has been changed, you can easily revert to the original format using the Terminal. As this is a system-wide setting change, please verify that it does not cause any issues in your environment before proceeding. If you are interested, feel free to try it out!

Thank you for reading!

Top comments (0)