Java Parse Long parseLong(final String s, final String fmt)

Here you can find the source of parseLong(final String s, final String fmt)

Description

parse Long

License

Apache License

Declaration

public static long parseLong(final String s, final String fmt) 

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 {
    private static final SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static long parseLong(final String s, final String fmt) {
        SimpleDateFormat sdf = new SimpleDateFormat(fmt);
        try {//from  ww  w . j a va2s. com
            Date t = sdf.parse(s);
            return t == null ? 0L : t.getTime();
        } catch (ParseException e) {
        }
        return 0L;
    }

    public static long parseLong(final String s) {
        try {
            Date t = sdf1.parse(s);
            return t == null ? 0L : t.getTime();
        } catch (ParseException e) {
        }
        return 0L;
    }

    public static Date parse(final String s, final String fmt) {
        SimpleDateFormat sdf = new SimpleDateFormat(fmt);
        try {
            return sdf.parse(s);
        } catch (ParseException e) {
        }
        return null;
    }

    public static Date parse(final String s) {
        try {
            return sdf1.parse(s);
        } catch (ParseException e) {
        }
        return null;
    }
}

Related

  1. parseLong(String d)
  2. parseLongtoTime(long date)