Java String to Timestamp stringToTimestamp(String date)

Here you can find the source of stringToTimestamp(String date)

Description

string To Timestamp

License

Open Source License

Declaration

public static long stringToTimestamp(String date) 

Method Source Code


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

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

public class Main {
    public static long stringToTimestamp(String date) {
        long time = -1L;
        if (date.indexOf(" ") == -1) {
            try {
                time = (new SimpleDateFormat("yyyy-MM-dd")).parse(date).getTime() / 1000;
            } catch (ParseException pe) {
            }/*from   ww w  .j a  v a2  s.  c o  m*/
        } else {
            try {
                time = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).parse(date).getTime() / 1000;
            } catch (ParseException pe) {
            }
        }
        return time;
    }
}

Related

  1. getTimeStampInSecond(String timeStr)
  2. isTimestamp(String str, boolean allowEmpty)
  3. isTimeStampValid(String timestamp)
  4. string2Timestamp(String dateString, String timezone)
  5. string2timestamp(String timeString)
  6. timestamp(String string)
  7. timeStamp2Date(String timestampString)
  8. timeStampToDate(String timeStamp)
  9. toTimeStamp(String argS)