Java Date Now getCurrentTimeAsString()

Here you can find the source of getCurrentTimeAsString()

Description

Get current Time.

License

Apache License

Return

Time in HHmmssSS format.

Declaration

public static String getCurrentTimeAsString() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.DecimalFormat;

import java.util.Calendar;

public class Main {
    /**/*from w  ww .  j  a v  a 2 s  . c o m*/
     * Get current Time.
     * @return   Time in HHmmssSS format.
     */
    public static String getCurrentTimeAsString() {

        Calendar calendar = Calendar.getInstance();

        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        int millisecond = calendar.get(Calendar.MILLISECOND);

        String mDateFormat = "";

        DecimalFormat twoDigitFormat = new DecimalFormat("00");

        mDateFormat = twoDigitFormat.format(hour) + twoDigitFormat.format(minute) + twoDigitFormat.format(second)
                + twoDigitFormat.format(millisecond);

        return mDateFormat;
    }
}

Related

  1. getCurrentTime(String pattern)
  2. getCurrentTime(String timeFormat)
  3. getCurrentTime2MysqlDateTime()
  4. getCurrentTimeAndDate()
  5. getCurrentTimeAsNumber()
  6. getCurrentTimeForFileName()
  7. getCurrentTimeForLog()
  8. getCurrentTimeForName()
  9. getCurrentTimeForUseInAFileName()