Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

So I'm looking for the command to change from 12h to 24h. Is there even such a command? I mean I can do it with the GUI but I need to be able to do it via terminal so I can put it in a bash script.

Here I want instead of the 12h format a 24h format.

share|improve this question
    
Do you mean to convert a given time? Or alter your system time display preference? Or something else? –  Andrew Ferrier Dec 17 '12 at 9:34
    
I want to alter my system time display preference (so the time display at the top right). I'll add this to make my question clearer. –  Philipp Dec 17 '12 at 10:17
add comment

1 Answer

up vote 4 down vote accepted

This is stored in the plist located at ~/Library/Preferences/com.apple.menuextra.clock under the key DateFormat.

Here's a quick primer:

  • EEE MMM d h:mm:ss a

12 Hour Mode with AM/PM

  • EEE MMM d h:mm:ss

12 Hour Mode without AM/PM

  • EEE MMM d H:mm:ss

24 Hour Mode

To apply any of these formatting strings, you can either use the defaults command at the Terminal, or if you're looking for a more programmable method, you can use the do shell script1 directive within Applescript.

To apply these via the Terminal, open it up and run the following command:

defaults write com.apple.menuextra.clock DateFormat -string 'EEE MMM d  H:mm:ss'

Substitute the string between the quotes with the version from above that you want.

The changes don't take effect immediately after running the command, I know you can logout/log back in for the change to be made, but I'm not aware of how to apply it immediately.


1 CyberCiti Primer on Shell Scripting via Applescript

share|improve this answer
    
Beautiful, works like a charm. Thank you! –  Philipp Dec 17 '12 at 12:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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