Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Convert datetime.datetime.now() to Number

Script:

datetime.datetime.now() 

will give

datetime.datetime(2019, 4, 9, 19, 55, 45, 938208)

And I want to convert like:

201949195545938208

I need this to create unique folder.

like image 893
Learnings Avatar asked Dec 28 '25 09:12

Learnings


1 Answers

Using strftime():

import datetime
print(datetime.datetime.now().strftime("%Y%m%d%H%M%S%z"))

OUTPUT:

20190409193226

EDIT:

Use %f, if you want to tag along the milliseconds as well.

like image 140
DirtyBit Avatar answered Dec 30 '25 22:12

DirtyBit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!