I have seen how to go from ISO formatted date such as 2007-01-14T20:34:22+00:00
, to a a more readble format with python datetime
.
Is there an easy way to generate a random ISO8601 date similar to this answer for datetime
strings?
I'd suggest using this Faker library.
pip install faker
It's a package that allows you to generate a variety of randomised "fake" data sets. Using Faker
below generates a random datetime
object which you can then convert to an ISO8601 string format using the datetime.datetime.isoformat
method.
import faker
fake = faker.Faker()
rand_date = fake.date_time() # datetime(2006, 4, 30, 3, 1, 38)
rand_date_iso = rand_date.isoformat() # '2006-04-30T03:01:38'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With