Java SQL Date Convert dateToStamp(String date)

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

Description

date To Stamp

License

Apache License

Declaration

public static String dateToStamp(String date) 

Method Source Code


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

import java.sql.Timestamp;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static String dateToStamp(String date) {
        try {//from   ww  w .j  a  v  a 2 s. c om
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(TIME_FORMAT);
            Date date1 = simpleDateFormat.parse(date);
            long ts = date1.getTime() / 1000;
            return String.valueOf(ts);
        } catch (Exception e) {

        }
        return String.valueOf(getDateStamp() / 1000);
    }

    public static Timestamp getTime() {
        String day = new SimpleDateFormat(TIME_FORMAT).format(Calendar.getInstance().getTime());
        return Timestamp.valueOf(day);
    }

    public static long getDateStamp() {
        return (long) System.currentTimeMillis() / 1000;
    }
}

Related

  1. dateToSql(Date dat)
  2. dateToSqlDate(Date date)
  3. dateToSqlDate(Date date)
  4. DateToSQLDate(Date pDate)
  5. dateToSQLDate(java.util.Date d)
  6. dateToSTR(Date data, String formato)
  7. dateToStr(java.util.Date date)
  8. dateToString(Date date)
  9. dateToString(Date date, String format)