Java tutorial
//package com.java2s; import java.util.*; public class Main { public static Date parseData(String text) { Calendar calendar = Calendar.getInstance(); if (text.contains(":")) { String[] time = text.split(":"); int hours = Integer.parseInt(time[0]); calendar.set(Calendar.MINUTE, Integer.parseInt(time[1])); calendar.set(Calendar.HOUR_OF_DAY, hours); return calendar.getTime(); } else if (text.contains("/")) { String[] date = text.split("/"); if (date.length == 3) { calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(date[0])); calendar.set(Calendar.MONTH, Integer.parseInt(date[1]) - 1); calendar.set(Calendar.YEAR, Integer.parseInt(date[2])); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR_OF_DAY, 0); return calendar.getTime(); } else if (date.length == 2) { calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(date[0])); calendar.set(Calendar.MONTH, Integer.parseInt(date[1]) - 1); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR_OF_DAY, 0); return calendar.getTime(); } } return null; } public static boolean contains(String str, boolean in, String... strs) { for (String s : strs) { if (in) { if (s.contains(str)) return true; } else { if (str.contains(s)) return true; } } return false; } public static int parseInt(String intValue) { if (intValue == null) return -1; try { return Integer.parseInt(intValue); } catch (NumberFormatException ex) { return -1; } } }