Java Time Format string2Long(String sourceTime, String dataFormat)

Here you can find the source of string2Long(String sourceTime, String dataFormat)

Description

string Long

License

Open Source License

Declaration


public static long string2Long(String sourceTime, String dataFormat) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

import java.util.Date;

public class Main {

    public static long string2Long(String sourceTime, String dataFormat) {

        long longTime = 0L;

        DateFormat f = new SimpleDateFormat(dataFormat);

        Date d = null;/*from   www.  j av a 2  s. co m*/

        try {

            d = f.parse(sourceTime);

        } catch (ParseException e) {

            e.printStackTrace();

        }

        longTime = d.getTime();

        return longTime;

    }

    public static Date parse(String strDate, String pattern) throws ParseException {
        try {
            return getFormatter(pattern).parse(strDate);
        } catch (ParseException pe) {
            throw new ParseException("Method parse in Class DateUtil  err: parse strDate fail.",
                    pe.getErrorOffset());
        }
    }

    private static SimpleDateFormat getFormatter(String parttern) {
        return new SimpleDateFormat(parttern);
    }
}

Related

  1. newDateTimeFormat()
  2. printDate(final long time, final String dateFormat)
  3. printFormatDate(long dateTime)
  4. setDateTimeFormat(String format)
  5. stdTimeFormat(Date date)
  6. string2long(String sourceTime, String dataFormat)
  7. stringDateTimeFormat(String dt2Format)
  8. stringTimeToLongTime(String time, String format)
  9. stringToTime(String format, String sDate)