Here you can find the source of getTimeStamp(String format)
Parameter | Description |
---|---|
format | The format of the timestamp. |
public static String getTimeStamp(String format)
//package com.java2s; /**/*from w w w .j a v a 2 s . c o m*/ * ? Copyright IBM Corporation 2016. * LICENSE: Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0 */ import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static final String TIMESTAMP_FORMAT = "yyyy-MM-dd_HH-mm-ss"; /** Gets a timestamp using the default format. * @return The current timestamp. */ public static String getTimeStamp() { return getTimeStamp(TIMESTAMP_FORMAT); } /** * Gets a timestamp using the given format. * @param format The format of the timestamp. * @return The current timestamp. */ public static String getTimeStamp(String format) { Date date = new Date(); SimpleDateFormat sdf; try { sdf = new SimpleDateFormat(format); } catch (NullPointerException | IllegalArgumentException e) { sdf = new SimpleDateFormat(TIMESTAMP_FORMAT); } return sdf.format(date); } }