Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

24H time from integer value

I wanted to convert 55 to 0055, similarly 655 to 0655 (so I can parse it with dateutil.parser).

I could do an if len == 2 add 00 + len == 3 add 0 statement, but I wonder if there’s a cleaner approach (e.g regex).

Any advice or help is much appreciated!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

zfill should do it, if you have ints to begin with and want to end with string for instance:

  str(55).zfill(4)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading