我的输入是时间(字符串变量),例如11:03
,我需要输出格式为HH:MM
。请帮忙。
我试过以下。但这只会比较时间是否相等。我需要知道格式是否匹配。
if (savedtime.compareTo(enteredtime)==0)
{
info(" The entered time format " + splitArr[i] + " matches with the saved time " + savedtime);
}
答案 0 :(得分:0)
如果语言是Java,那么请查看DateFormat,您可以在其中指定指定的模式。
在其他语言中也有类似的可能性。
SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
String dateInString = "31-08-1982 10:20:56";
Date date = sdf.parse(dateInString);
System.out.println(date); //Tue Aug 31 10:20:56 SGT 1982
示例摘自:http://www.mkyong.com/java/java-date-and-calendar-examples/
答案 1 :(得分:0)
如果使用Java编程并使用Joda-Time,请参阅the doc on formatting。然后在StackOverflow中搜索已经回答的许多类似问题。