Java SQL Date Parse parseDate(String strDate)

Here you can find the source of parseDate(String strDate)

Description

parse Date

License

Apache License

Declaration

public static Date parseDate(String strDate) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {

    public static Date parseDate(String strDate) {
        long r = 0;
        try {//from w  ww.j  ava  2s  .  c  om
            StringTokenizer token = new StringTokenizer(strDate, " ");
            String date = token.nextToken();
            Date now = java.sql.Date.valueOf(date);
            r = now.getTime();
            try {
                String time = token.nextToken();
                StringTokenizer tkTime = new StringTokenizer(time, ":");
                r += Integer.parseInt(tkTime.nextToken()) * 60 * 60 * 1000;
                r += Integer.parseInt(tkTime.nextToken()) * 60 * 1000;
                r += Integer.parseInt(tkTime.nextToken()) * 1000;
            } catch (Exception ex) {
                r = now.getTime();
            }
        } catch (Exception ex) {
            return new Date();
        }
        return new Date(r);
    }

    public static String getTime() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(currentTime);
        String min;
        min = dateString.substring(14, 16);
        return min;
    }
}

Related

  1. parseDate(String date)
  2. parseDate(String dateStr, String formatStr)
  3. parseDate(String exifDate)
  4. parseDate(String s)
  5. parseDate(String s)
  6. parseDate(String strFormat, String dateValue)
  7. parseDate(String value, String format)
  8. parseDate2(Date date, String pattern)
  9. parseDateE(Date dt)