String str = textField.getText();
if (str.length() == 14)
{
try
{
int year = Integer.parse(str.substring(0, 4));
int month = Integer.parse(str.substring(4, 6));
int date = Integer.parse(str.substring(6, 8));
int hour = Integer.parse(str.substring(8, 10));
int minute = Integer.parse(str.substring(10, 12));
int second = Integer.parse(str.substring(12, 14));
//接下来判断是否为合法的日期格式
...
}
catch (Exception e)
{
e.printStackTrace();
}
}
if (str.length() == 14)
{
try
{
int year = Integer.parse(str.substring(0, 4));
int month = Integer.parse(str.substring(4, 6));
int date = Integer.parse(str.substring(6, 8));
int hour = Integer.parse(str.substring(8, 10));
int minute = Integer.parse(str.substring(10, 12));
int second = Integer.parse(str.substring(12, 14));
//接下来判断是否为合法的日期格式
...
}
catch (Exception e)
{
e.printStackTrace();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货