Here you can find the source of getCurrentDateTime(String dateFormat)
public static String getCurrentDateTime(String dateFormat)
//package com.java2s; /*/* w w w . j av a2 s .co m*/ * Title: TRS ?????? * Copyright: Copyright (c) 2004-2005, TRS?????????????. All rights reserved. * License: see the license file. * Company: TRS?????????????(www.trs.com.cn) * * Created on 2005-5-11 */ import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String getCurrentDateTime() { return getCurrentDateTime("yyyy-MM-dd HH:mm:ss"); } public static String getCurrentDateTime(String dateFormat) { return timeMillisToString(System.currentTimeMillis(), dateFormat); } public static String timeMillisToString(long timeMillis) { return timeMillisToString(timeMillis, "yyyy-MM-dd HH:mm:ss"); } public static String timeMillisToString(long timeMillis, String dateFormat) { if ("".equals(dateFormat) || dateFormat == null) { return null; } try { return new SimpleDateFormat(dateFormat).format(new Date(timeMillis)); } catch (Exception e) { return null; } } }