Exemplo n.º 1
0
 @SuppressWarnings("deprecation")
 public Date convertToDate(String dateS, Date date) {
   if (date == null) date = new Date(2000, 01, 01);
   date.setYear(Integer.parseInt(dateS.split("-")[0]) - 1900);
   date.setMonth(Integer.parseInt(dateS.split("-")[1]) - 1);
   date.setDate(Integer.parseInt(dateS.split("-")[2]));
   return date;
 }
Exemplo n.º 2
0
  private static Long ParseDateToTimeStamp(String dateString) {
    Date dateUtil = null;
    java.sql.Date dateSQL = null;
    String dateArray[] = new String[2];
    DateFormat simpleDate = null;
    String format = "yyyy-mm-dd hh:mm:ss";
    if (dateString != null) {
      try {
        if (dateString.contains("T")) {
          dateArray = dateString.split("T");
          if (dateArray[1].contains("Z")) {
            dateArray[1] = dateArray[1].substring(0, dateArray[1].length() - 1);
          }
          dateString = dateArray[0] + " " + dateArray[1] + ":00";

        } else {
          if (dateString.contains(".")) {
            dateString = dateString.substring(0, dateString.length() - 2);
          } else {
            dateString += ":00";
            format = "dd-mm-yyyy hh:mm:ss";
          }
        }
        simpleDate = new SimpleDateFormat(format);
        System.out.println("String " + dateString);
        System.out.println("util " + simpleDate.parse(dateString));
        dateUtil = simpleDate.parse(dateString);
        dateSQL = new java.sql.Date(dateUtil.getTime());
        dateSQL.setMonth(Integer.parseInt(dateString.split("-")[1]) - 1);
        System.out.println(dateSQL);
      } catch (ParseException e) {
        e.printStackTrace();
      }
    }
    java.sql.Timestamp timestamp = new Timestamp(dateSQL.getTime());
    return timestamp.getTime();
  }