【发布时间】:2013-03-29 12:32:18
【问题描述】:
我目前正在用 Java 制作拍卖程序,我正在尝试制定截止日期,但是我的日期一直显示为 (7/04/2013 11:22),有没有办法使用 String.format 添加当它是一个数字的日子时,这个日期的前导零?
String timeOne = Server.getDateTime(itemArray.get(1).time).toString()
稍后当我尝试对其进行子字符串时,它会导致我出现问题,并且它的长度小于 17 个字符。
提前致谢,詹姆斯。
【问题讨论】:
-
你能添加你的代码吗?
-
我猜你正在使用
SimpleDateFormat或类似的东西来格式化日期。如果是这样,请使用正确的格式,即 总是 将天返回为两位数。如果是SimpleDateFormat:dd。 -
Server.getDateTime()的返回类型是什么?
-
日期和时间存储在日历项目中。但是,当我从日历对象中获取时间时,它会返回不带前导零的时间。
-
不要不尝试解析日历的
toString表示。来自Javadoc -Return a string representation of this calendar. This method is intended to be used only for debugging purposes, and the format of the returned string may vary between implementations