pythondateformatstrftime

Python strftime %A fixed length


I am using the following date format:

d.strftime("%A, %d %B %Y %H:%m")

and since the length of the weekday (%A) changes, I would like to always print the weekday with 10 characters, pad spaces to the left, and align it right.

Something like

d.strftime("10%A, %d %B %Y %H:%m")

What is the simplest way?


Solution

  • How about this:

    d.strftime("%A") + " " * (10 - len(d.strftime("%A")) + "," + d.strftime("%d %B %Y %H:%m")
    

    Jack