Java Time Format getTime(String dateStr, String format)

Here you can find the source of getTime(String dateStr, String format)

Description

get Time

License

Apache License

Declaration

public static long getTime(String dateStr, String format) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static long getTime(String dateStr, String format) {
        long time = -1;
        Date date = getDate(dateStr, format);
        if (date != null) {
            time = getDate(dateStr, format).getTime();
        }//w ww  .j  a  v  a 2 s.  c  o  m
        return time;
    }

    public static long getTime(String dateStr) {
        long time = -1;
        String format = "yyyy-MM-dd HH:mm:ss";
        Date date = getDate(dateStr, format);
        if (date != null) {
            time = getDate(dateStr, format).getTime();
        }
        return time;
    }

    public static Date getDate(String dateStr, String formatString) {
        Date date = null;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(formatString);
            date = sdf.parse(dateStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

    public static Date getDate(String dateStr) {
        return getDate(dateStr, "yyyy-MM-dd HH:mm:ss");
    }
}

Related

  1. getTime(Date dt, String format)
  2. getTime(Date time, int format, Locale locale)
  3. getTime(DateFormat df)
  4. getTime(int format)
  5. getTime(long time, int timeFormat)
  6. getTime(String dateStr, String formate)
  7. getTime(String format)
  8. getTime(String format, String date)
  9. getTime(String timeFormat)