Java Time Format getTime(String dateStr, String formate)

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

Description

get Time

License

Apache License

Declaration

public static long getTime(String dateStr, String formate) 

Method Source Code


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

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static long getTime(String dateStr, String formate) {
        Date date;/*w  w w.ja  v  a2s  .c  o  m*/
        try {
            date = getDate(dateStr, formate);
            return date.getTime();
        } catch (ParseException e) {
            return -1;
        }
    }

    public static long getTime(String dateStr) {
        return getTime(dateStr, DEFAULT_FORMAT);
    }

    public static String getDate(Date date, String formate) {
        SimpleDateFormat sf = new SimpleDateFormat(formate);
        return sf.format(date);
    }

    public static Date getDate(String dateStr, String formate) throws ParseException {
        SimpleDateFormat sf = new SimpleDateFormat(formate);
        return sf.parse(dateStr);
    }
}

Related

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