Java Date Now getCurrentDateTime(String dateFormat)

Here you can find the source of getCurrentDateTime(String dateFormat)

Description

get Current Date Time

License

Open Source License

Declaration

public static String getCurrentDateTime(String dateFormat) 

Method Source Code


//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;
        }
    }
}

Related

  1. getCurrentDateTime()
  2. getCurrentDateTime()
  3. getCurrentDateTime()
  4. getCurrentDateTime()
  5. getCurrentDateTime()
  6. getCurrentDateTime(String format)
  7. getCurrentDateTimeForShow()
  8. getCurrentDateTimeISO8601()
  9. getCurrentDateTimeObj(String dateTime, String format)