Java Timestamp Field getNotNullTimestampValue(String timestamp, String format)

Here you can find the source of getNotNullTimestampValue(String timestamp, String format)

Description

get Not Null Timestamp Value

License

Apache License

Declaration

public static Timestamp getNotNullTimestampValue(String timestamp, String format) 

Method Source Code


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

import java.sql.Timestamp;

import java.text.SimpleDateFormat;

public class Main {

    public static Timestamp getNotNullTimestampValue(String timestamp, String format) {
        Timestamp value;/*w  ww  .  j a  v  a2s .co  m*/
        try {
            if (timestamp == null || timestamp.equals("")) {
                value = new Timestamp(System.currentTimeMillis());
            } else {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
                value = new Timestamp(simpleDateFormat.parse(timestamp).getTime());
            }
        } catch (Exception e) {
            e.printStackTrace();
            value = new Timestamp(System.currentTimeMillis());
        }
        return value;
    }
}

Related

  1. getNanos(Timestamp timestamp)
  2. getNanoString(Timestamp timestamp, boolean full, char nanoSep)
  3. getNbHours(Timestamp dateA, Timestamp dateB)
  4. getNextDayStart(java.sql.Timestamp stamp)
  5. getNextTimestamp(Timestamp previous, long nrDays)
  6. getNowTimestamp()
  7. getNowTimeStamp()
  8. getNowTimeStamp()
  9. getOffsetDaysTime(Timestamp sysDate, int offsetDays)