Here you can find the source of getCurrentDate(String pattern)
Parameter | Description |
---|---|
pattern | The SimpleDateFormat pattern to use (e.g. "yyyyMMddHHmmss"). |
public static String getCurrentDate(String pattern)
//package com.java2s; /*// w w w .j ava 2 s. com * Copyright (c) Mirth Corporation. All rights reserved. * * http://www.mirthcorp.com * * The software in this package is published under the terms of the MPL license a copy of which has * been included with this distribution in the LICENSE.txt file. */ import java.text.SimpleDateFormat; import java.util.Date; public class Main { /** * Formats the current date into a string according to a specified pattern. * * @param pattern * The SimpleDateFormat pattern to use (e.g. "yyyyMMddHHmmss"). * @return The current formatted date string. */ public static String getCurrentDate(String pattern) { return formatDate(pattern, new Date()); } /** * Formats a java.util.Date object into a string according to a specified pattern. * * @param pattern * The SimpleDateFormat pattern to use (e.g. "yyyyMMddHHmmss"). * @param date * The java.util.Date object to format. * @return The formatted date string. */ public static String formatDate(String pattern, Date date) { SimpleDateFormat formatter = new SimpleDateFormat(pattern); return formatter.format(date); } }