簡體   English   中英

字符串格式:2 => 02

[英]String.format: 2 => 02

       String formatted = String.format("%d:%d", 2, 5);

我會 output 2:5

但我想要: 02:05 ,並且我不希望數字 > 9 的額外零。在這種情況下,它應該顯示為: 10:35

如何修改String.format方法以這種方式工作?

謝謝!

您應該能夠使用這種格式:

String formatted = String.format("%02d:%02d", 2, 5);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM