不用正则的情况下,如下代码:
package src; import java.text.SimpleDateFormat; public class Main { public static void main(String args[]){ boolean b = checkTime("2014-12-3 15:17:56"); System.out.println(b); } public static boolean checkTime(String time) { boolean falg = false; try { new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(time); falg = true; } catch (Exception ex) { falg = false; } return falg; } }
时间: 2024-10-09 04:40:47