Here you can find the source of getTimestamp(Date time)
Parameter | Description |
---|---|
time | Time to convert, or null for current time. |
public static String getTimestamp(Date time)
//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"); } }