Java Time Parse getTimeX(String dateStr)

Here you can find the source of getTimeX(String dateStr)

Description

get Time X

License

Artistic License

Declaration

public static long getTimeX(String dateStr) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static long getTimeX(String dateStr) {
        long time = 0;
        time = getDate(dateStr).getTime() / 1000;
        return time;
    }// w  w w  . j  a v  a2  s.  c  o m

    public static long getTimeX(String dateStr, String format) {
        long time = 0;
        time = getDate(dateStr, format).getTime() / 1000;
        return time;
    }

    public static long getTimeX(Date date) {
        long time = 0;
        time = date.getTime() / 1000;
        return time;
    }

    public static long getTime(String dateStr, String format) {
        long time = -1;
        Date date = getDate(dateStr, format);
        if (date != null) {
            time = getDate(dateStr, format).getTime();
        }
        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. getTimeFromJsToJava(String date)
  2. getTimeFromString(String time)
  3. getTimeList(String start, String end, int pitch)
  4. getTimeStr(String date1, String date2)
  5. getTimeWithStr(String source, String pattern)
  6. isDateTime(String dateTime)
  7. isDateTime(String dateTime, String pattern)
  8. isDatetimeParsable(String value)
  9. isFromartDate(String time)