Python time formatting gives error on Windows but works on mac

34 views Asked by At

I am using this code to format dates:

from datetime import datetime

pictureData = datetime.strptime('2022-01-03', '%Y-%m-%d')
pictureData = pictureData.strftime("%Y-%-m-%-d")
print(pictureData)

This works great on Mac, printing 2022-1-3; but gives this error on Windows:

Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\file.py", line 17, in <module>
pictureData = pictureData.strftime("%Y-%-m-%-d")
ValueError: Invalid format string

I want to remove the padding zero before the 01 and 03. How can I make this work in a cross-platform way?

0

There are 0 answers