Java Timestamp Format format(final Date date)

Here you can find the source of format(final Date date)

Description

format

License

Apache License

Declaration

public static String format(final Date date) 

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 FORMAT_PATTERN = "yyyy-MM-dd kk:mm:ss.SSS";

    public static String format(final Date date) {
        String milliseconds = new SimpleDateFormat(FORMAT_PATTERN).format(date);
        if (date instanceof Timestamp) {
            Timestamp timestamp = (Timestamp) date;
            final int nanos = timestamp.getNanos();
            int microseconds = nanos / 1000;
            milliseconds = milliseconds.substring(0, milliseconds.indexOf(".") + 1)
                    + String.format("%06d", microseconds);
        }/*  ww  w.  j ava  2 s. co  m*/

        return milliseconds;
    }
}

Related

  1. format(BigDecimal data)
  2. format(Date aTs_Datetime)
  3. format(Date date)
  4. format(Date date, String format)
  5. format(Date time, String pattern)
  6. formatDate(Date date, String pattern)
  7. formatDate(Date date, String pattern)
  8. formatDate(java.util.Date d)
  9. formatDate(java.util.Date date)