# Add millisecond formatting support to datetime.strftime

**URL:** <https://discuss.python.org/t/add-millisecond-formatting-support-to-datetime-strftime/105115>\
**Category:** Ideas\
**Created:** [November 28, 2025, 1:21pm UTC](https://discuss.python.org/t/add-millisecond-formatting-support-to-datetime-strftime/105115 "2025-11-28T13:21:16Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![jb2170](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jb2170/32/24298_2.png) [@jb2170](https://discuss.python.org/u/jb2170)\
**Post date:** [August 30, 2026, 9:00pm UTC](https://discuss.python.org/t/add-millisecond-formatting-support-to-datetime-strftime/105115/12 "2026-08-30T21:00:48Z")

</div>

I’ve done some more thinking. It looks a bit contradictory to have

- `%Nf` means “take the integer `%f` (microsecond number) and _truncate_ to the _highest_ `N` of 6 digits”
- `%Nm` means “take the integer `%m` (month number) and _pad_ to `N` digits”

but also `%.Nf` instead of `%Nf` is weird, arguably worse, because

1. `.` is not used in any `strftime(3)` specifiers (I was confused with \*`printf(3)`\*, my bad 😅 ).
2. Even if taking inspiration from `printf(3)` for this thread, microseconds is not a float (which `printf(3)`'s and Python’s precision `.` truncates to `N` digits) but rather it is an integer, which `printf(3)`'s (and Python’s upcoming [PEP 786](https://discuss.python.org/t/106907)’s) `.` _pads_ to a _minimum_ number of digits, whereas we want to format to a fixed number of digits (6 for microseconds) and then truncated to the highest `N`.

Either syntax `%Nf` or `%.Nf` is going to be exceptional because of the niche task of formatting an integer to 6 digits, then truncating to the _highest_ `N`.

However, `%f` is not part of `strftime(3)`. It’s explicitly a [Python extension](https://docs.python.org/3/library/datetime.html#:~:text=seconds%2E-,When,available%29%2E). So either syntax we choose we don’t have to worry about it ‘breaking’ `strftime(3)`. I think it reduces to just a question of “which syntax looks nicer / is most intuitive?”.

I think I prefer the `%Nf` syntax based off the understandable questions of

> [@karolinepauls](#):
>
> Would `%.3f` also produce the decimal point?

etc, firstly from a visual analysis to stop confusion

\> “there’s a `.` in the specifier, where is the `.` in the output?”

and secondly as @jsbueno points out [Rust’s strftime](https://docs.rs/chrono/latest/chrono/format/strftime/index.html#:~:text=4-,%25f) has different behavior for `%.3f` and `%3f`, and we want the behavior of the latter.

* * *

TLDR: I retract my `%.Nf` inquiry and I’m +1 on `%Nf`.

---

_[View the full topic](https://discuss.python.org/t/add-millisecond-formatting-support-to-datetime-strftime/105115)._
