Java Timestamp Now currentTimestamp2String(String pattern)

Here you can find the source of currentTimestamp2String(String pattern)

Description

current Timestamp String

License

Open Source License

Declaration

public static String currentTimestamp2String(String pattern) 

Method Source Code


//package com.java2s;
import java.sql.Timestamp;

import java.text.SimpleDateFormat;

import java.util.Date;

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

    public static String currentTimestamp2String(String pattern) {
        return timestamp2String(currentTimestamp(), pattern);
    }//w  w w  .  j av  a  2  s. com

    public static String timestamp2String(Timestamp timestamp, String pattern) {
        if (timestamp == null) {
            throw new java.lang.IllegalArgumentException("timestamp null illegal");
        }
        if (pattern == null || pattern.equals("")) {
            pattern = PATTERN_STANDARD;
        }
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(new Date(timestamp.getTime()));
    }

    public static Timestamp currentTimestamp() {
        return new Timestamp(new Date().getTime());
    }
}

Related

  1. currentTimeStamp()
  2. currentTimeStamp()
  3. currentTimestamp()
  4. currentTimestamp()
  5. currentTimestamp()
  6. currentTimestampPlus(final long seconds)
  7. generateTimestamp()
  8. generateTimeStamp()
  9. generateTimestamp()