Skip to content
Advertisement

Generate list of random datetimes in ISO8601 format in Python

I want to generate a list of length n with random datetime strings in Python within a range.

JavaScript

I had asked a similar question before, but I did not use the correct format for datetime.What is the best way to achieve this?

Advertisement

Answer

Modifying the answer here for your format: https://stackoverflow.com/a/553448/7942856

JavaScript

Outputs:

JavaScript

Then if you want the text ISO format, simply call .isoformat() on your list elements.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement