Java Timestamp Create getTimestamp(Date time)

Here you can find the source of getTimestamp(Date time)

Description

Converts a time to timestamp format.

License

Mozilla Public License

Parameter

Parameter Description
time Time to convert, or null for current time.

Return

Time in timestamp format.

Declaration

public static String getTimestamp(Date time) 

Method Source Code

//package com.java2s;
/**//from   ww w. j a  v  a  2 s .  c  o m
 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
 * If a copy of the MPL was not distributed with this file, You can obtain one at
 * http://mozilla.org/MPL/2.0/.
 * 
 * This Source Code Form is also subject to the terms of the Health-Related Additional
 * Disclaimer of Warranty and Limitation of Liability available at
 * http://www.carewebframework.org/licensing/disclaimer.
 */

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

public class Main {
    /**
     * Converts a time to timestamp format.
     * 
     * @param time Time to convert, or null for current time.
     * @return Time in timestamp format.
     */
    public static String getTimestamp(Date time) {
        return getTimestampFormatter().format(time == null ? new Date() : time);
    }

    /**
     * Returns a formatter capable of producing and parsing timestamps.
     * 
     * @return Formatter for timestamps.
     */
    private static SimpleDateFormat getTimestampFormatter() {
        return new SimpleDateFormat("yyyyMMddHHmmssz");
    }
}

Related

  1. getTimeStamp(Date date)
  2. getTimeStamp(Date date)
  3. getTimeStamp(Date date)
  4. getTimestamp(Date date)
  5. getTimestamp(Date date, String timestampPattern)
  6. getTimestamp(final File file)
  7. getTimestamp(final LocalDate date)
  8. getTimestamp(final Map map, final Object key)
  9. getTimestamp(int offset)