Tuesday, August 27, 2013

How to get 12-hour clock in i3

At the beginning of our look into some neat tricks with i3, we are going to see how to get a 12 hour clock (with seconds) under i3. This assumes that you have the proper packages installed

  • i3-wm (sometimes called i3, either as a standalone or meta package)
  • i3status
  • i3bar
We are going to edit the global configuration file for i3status, a program that creates a status line for i3bar. The file is located over at /etc/i3status.conf, in case you know what you're doing and want to jump ahead of this article.

Open that file as root, and you should see something that looks like this:

Where it says time{format = "_"}, that is where the magic happens. The string supplied here is passed through a C function called strftime, which is the standard timestamp formatting tool across all Unix-like systems. The format they use with 24-hour clocks has the "%H" in the string. Find where it says "%H" inside of that string, and change it to "%l" to get the 12-hour time.

To see all of the options available, type "man strftime" at your terminal emulator.



 The format I use across all of my bars and time-tools is "%a %b %_d %Y %H-> %l:%M:%S", which comes across like this:

5 comments:

  1. Thanks so much for this! Just wanted to point out that you have a typo where it says "change it to %l to get the 24-hour time" it should say 12 hour time.

    And for any lazy folks out there, add %p at the very end to get AM/PM.

    ReplyDelete
    Replies
    1. Thanks for the heads up! After 2 years I finally change that 2 character typo. That's procrastination right there!

      Delete
  2. Thanks author for the article and anonymous comment-er for essential addition.

    ReplyDelete
  3. Awesome! I'm still learning i3 (gaps) so tips like this help a great deal.

    ReplyDelete
  4. Just a note, don't edit /etc/i3status.conf! Copy it to ~/.i3tstatus.conf.

    See `man i3status` for more details :)

    ReplyDelete