Java Date Now getCurrentDateTime()

Here you can find the source of getCurrentDateTime()

Description

Gets the current date time.

License

Open Source License

Return

the current date time

Declaration

public static String getCurrentDateTime() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.DateFormat;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    /**/* w  ww  .j  a  v  a 2 s .com*/
     * Gets the current date time.
     * 
     * @return the current date time
     */
    public static String getCurrentDateTime() {
        String ranNum = "";
        DateFormat formatter = new SimpleDateFormat("MMM");
        SimpleDateFormat monthParse = new SimpleDateFormat("MM");
        DateFormat dformatter = new SimpleDateFormat("DD");
        SimpleDateFormat dateParse = new SimpleDateFormat("DD");
        Calendar cal = Calendar.getInstance();
        String month = Integer.toString(cal.get(Calendar.MONTH) + 1);
        String date = Integer.toString(cal.get(Calendar.DATE) + 1);
        try {
            ranNum = "_" + dformatter.format(dateParse.parse(date)) + formatter.format(monthParse.parse(month))
                    + "_" + Integer.toString(cal.get(Calendar.HOUR_OF_DAY))
                    + Integer.toString(cal.get(Calendar.MINUTE));
        } catch (Exception e) {
        }
        return ranNum;
    }
}

Related

  1. getCurrentDateTime()
  2. getCurrentDateTime()
  3. getCurrentDateTime()
  4. getCurrentDateTime()
  5. getCurrentDateTime()
  6. getCurrentDateTime()
  7. getCurrentDateTime(String dateFormat)
  8. getCurrentDateTime(String format)
  9. getCurrentDateTimeForShow()