Is it a way to replace/customize the default __str__
of datetime?
from datetime import datetime
x = datetime.now() # x can be any date from parameters
print(x) # str(x) returns 2020-10-07 10:38:08.048291 too, but I want a different format
I need to change the default __str__
behave for other functions like json.dump(x, default=str)
.
x = 12, 'abc', datetime.now(), 223, ....
json.dump(x, default=str)