Java Timestamp Create getTimestampFromDate(String d)

Here you can find the source of getTimestampFromDate(String d)

Description

get Timestamp From Date

License

Apache License

Declaration

public static long getTimestampFromDate(String d) 

Method Source Code


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

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

public class Main {
    static final DateFormat DATE_NAME_FORMAT = new SimpleDateFormat("yyyy/MM/dd");

    public static long getTimestampFromDate(String d) {
        try {/*from   ww  w.j av  a  2 s .  co  m*/
            return DATE_NAME_FORMAT.parse(d).getTime();
        } catch (ParseException e) {
            System.err.println(d + " getTimestampFromDate " + e.getMessage());
        }
        return 0;
    }

    public static int getTimestampFromDate(java.sql.Date d) {
        if (d != null) {
            return (int) (d.getTime() / 1000);
        }
        return 0;
    }
}

Related

  1. getTimestampFormat()
  2. getTimestampFormat()
  3. getTimestampFormat()
  4. getTimestampFormatter()
  5. getTimestampFromDate(Date d)
  6. getTimestampFromDateTime(DateTime dateTime)
  7. getTimeStampFromISOString(String isoString)
  8. getTimestampFromString(String dateStr)
  9. getTimestampFromString(String dateString, String dateFormat)