Java Timestamp getCurFullTimestampStr()

Here you can find the source of getCurFullTimestampStr()

Description

get Cur Full Timestamp Str

License

Apache License

Declaration

public static final String getCurFullTimestampStr() 

Method Source Code


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

import java.sql.Timestamp;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static final String getCurFullTimestampStr() {
        return formatTimestamp(getCurFullTimestamp());
    }/* w  ww.  ja  va2s  .  co  m*/

    /**
      * @param aDate
      * @return formated time by yyyy-MM-dd HH:mm:ss
      */
    public static final <T extends Date> String formatTimestamp(T date) {
        if (date == null)
            return null;
        SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return timestampFormat.format(date);
    }

    public static final String formatTimestamp(Long mills) {
        return formatTimestamp(new Date(mills));
    }

    public static final Timestamp getCurFullTimestamp() {
        return new Timestamp(System.currentTimeMillis());
    }

    /**
      * @param date
      * @param pattern: Date format pattern
      * @return
      */
    public static final <T extends Date> String format(T date, String pattern) {
        if (date == null)
            return null;
        try {
            SimpleDateFormat df = new SimpleDateFormat(pattern);
            String result = df.format(date);
            return result;
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. fromTimestamp(Timestamp timestamp)
  2. generateTimestamp()
  3. getBeforeDate(final Timestamp baseTime, final int period, final int unit)
  4. getCalendarTimestamp(Calendar cal)
  5. getCurentTimestamp()
  6. getCurrTimestamp()
  7. getCurTime2Timestamp()
  8. getCurTimestamp()
  9. getCurTimestamp()