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

how to add Zero to Format Time using String Format class?

i want to format date and time with given number like

        val time = 4
           val hour =5 

how to write it like that 4:05

        String.format("%d:%d",time.hours ,time.minutes)

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 :

use this format:

  String.format("%02d:%02d",time.hours ,time.minutes)

use %02d instead of %d

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