2

I'm trying to add a timestamp to the beginning of my bash prompt in the format of a 12 hour HH:MM:SS AM/PM clock, and as of now, I've had no luck. Here's a couple things I've tried.

I've tried date +%r but that only updates each time my ~/.bashrc is reloaded.

I've tried \D{%T} but that displays 24-hour time.

I've tried \@ but that only displays HH:MM AM/PM.

I've tried \t but that displays 24-hour time.

I've tried \T but that does not show AM/PM.

Am I missing something, or is there some way to do this?

3
  • 1
    Does \D{%r} do what you want? Commented Jul 15, 2016 at 0:35
  • @steeldriver Yes! Thank you! I really should have tried that based on what I just said eh? Commented Jul 15, 2016 at 0:37
  • \@ suits me better, thanks for documenting that :) Commented May 17, 2021 at 23:54

1 Answer 1

3

\D{%r} displays 12 hour time in the HH:MM:SS AM/PM format.

2
  • greate,where do you find it?
    – Alice
    Commented Mar 18, 2019 at 12:38
  • 1
    In my opinion it would be nice if they removed the misleading leading 0 from the hour. Commented May 17, 2021 at 23:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .