is there a way to add trailing zeroes into datetime as string?

Try this.

def f(string, suffix='.00', length=22):
    if len(string) == length:
        return string
    return string + suffix[-(length - len(string)):]

suite = {
    '2020-11-04T19:48:19.9': '2020-11-04T19:48:19.90',
      '2020-11-04T19:48:20': '2020-11-04T19:48:20.00',
   '2020-11-04T19:48:20.00': '2020-11-04T19:48:20.00',

for case, expected in suite.items():
    assert f(case) == expected

Check it at

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top