所以我有一个字符串military time format
:“1532”对应于3:32 pm。 我想写一个方法来检查时间字符串中的每个数字是否是一个合适的数字。所以第一个元素不能大于2或等于0,等等。目前,我的代码没有超过第二条日志语句,我希望你们可以帮忙!如何检查字符串中的值?
干杯!
String mOpen = "1532";
Log.d("hoursTesting","pass1, length is > 2");
if(mOpen.getText().length() == 4)
{
Log.d("hoursTesting","pass2, length is == 4");
char[] tempString = mOpen.getText().toString().toCharArray();
if(tempString[0] != 0 && tempString[0] < 3)
{
Log.d("hoursTesting","pass3, first index is != 0 and < 3");
if(tempString[0] == 1)
{
Log.d("hoursTesting","pass4, first index is 1");
if(tempString[2] <= 5)
{
Log.d("hoursTesting","pass5, third index is <= 5, success!");
}
}
else //tempString[0] is equal to 2
{
Log.d("hoursTesting","pass4, first index is 2");
if(tempString[1] < 4)
{
Log.d("hoursTesting","pass5, second index is <3");
if(tempString[2] <= 5)
{
Log.d("hoursTesting","pass6, third index is <= 5, success!");
}
}
}
}
}
您是否尝试过调试?如果你能直观地看到每一步发生的事情,这可能是显而易见的。 –
你需要支持闰秒吗? – Jasen