Java Calendar Calculate getTimeStr3(Calendar timeInstance)

Here you can find the source of getTimeStr3(Calendar timeInstance)

Description

Returns a string of the time instance in string format for internal use.

License

Open Source License

Parameter

Parameter Description
timeInstance calendar instance

Return

time in string

Declaration

public static String getTimeStr3(Calendar timeInstance) 

Method Source Code


//package com.java2s;
import java.util.*;

public class Main {
    /**/*from  w  w  w.java 2 s .  c  o  m*/
     * Returns a string of the time instance in string format for internal use. <br><br>
     *  Complete date plus hours, minutes and seconds:<br>
     *  YYYYMMDDhhmmss (eg 19970716192030)
     * @param timeInstance calendar instance
     * @return time in string 
     */
    public static String getTimeStr3(Calendar timeInstance) {
        Calendar time = timeInstance;
        int field;
        String year = "", month = "", day = "", hour = "", minute = "", second = "";
        String timeStr = "";

        field = time.get(Calendar.YEAR);
        if (field < 10) {
            year = "000";
        }
        year = year + Integer.toString(field);

        field = time.get(Calendar.MONTH) + 1;
        if (field < 10) {
            month = "0";
        }
        month = month + Integer.toString(field);

        field = time.get(Calendar.DAY_OF_MONTH);
        if (field < 10) {
            day = "0";
        }
        day = day + Integer.toString(field);

        field = time.get(Calendar.HOUR_OF_DAY);
        if (field < 10) {
            hour = "0";
        }
        hour = hour + Integer.toString(field);
        field = time.get(Calendar.MINUTE);
        if (field < 10) {
            minute = "0";
        }
        minute = minute + Integer.toString(field);
        field = time.get(Calendar.SECOND);
        if (field < 10) {
            second = "0";
        }
        second = second + Integer.toString(field);

        timeStr = year + month + day + hour + minute + second;
        return timeStr;
    }
}

Related

  1. equals(Calendar calendar1, Calendar calendar2)
  2. FormatTime(Calendar p_time, boolean p_showMilliseconds)
  3. getCalendar(long millis)
  4. getGregorianCalendar(String yyyymmdd)
  5. getLongTime(Calendar cal)
  6. getTimeString(Calendar cal)
  7. getTimeStrWithMillisecond(Calendar timeInstance)
  8. isAfterWorkTime(Calendar start)
  9. isInWorkTime(Calendar start)