Java Calendar Create getCalendarDate(Calendar calendar)

Here you can find the source of getCalendarDate(Calendar calendar)

Description

get Calendar Date

License

Open Source License

Declaration

public static final String getCalendarDate(Calendar calendar) 

Method Source Code


//package com.java2s;

import java.util.Calendar;

public class Main {

    public static final String getCalendarDate(Calendar calendar) {
        String year = String.valueOf(calendar.get(Calendar.YEAR));

        String month = String.valueOf(calendar.get(Calendar.MONTH) + 1);
        if (month.length() < 2)
            month = "0" + month;

        String date = String.valueOf(calendar.get(Calendar.DATE));
        if (date.length() < 2)
            date = "0" + date;

        String hours = String.valueOf(calendar.get(Calendar.HOUR_OF_DAY));
        if (hours.length() < 2)
            hours = "0" + hours;

        /*String hours = String.valueOf(calendar.get(Calendar.HOUR));
        if (calendar.get(Calendar.AM_PM ) == 1)
           hours = String.valueOf(Integer.parseInt(hours) + 12);
        if (hours.length() < 2)//  w  ww  .j  a v a 2  s  . com
           hours = "0" + hours;*/

        String minutes = String.valueOf(calendar.get(Calendar.MINUTE));
        if (minutes.length() < 2)
            minutes = "0" + minutes;

        /*String second = String.valueOf(calendar.get(Calendar.SECOND));
        if (second.length() < 2)
           second = "0" + second;*/

        return year + "/" + month + "/" + date + " " + hours + ":" + minutes;
    }
}

Related

  1. getCalendarBefore(int i)
  2. getCalendarByName(String timeZone)
  3. getCalendarBySpecific(int year, int month, int date, int hour)
  4. getCalendarByValue(String timeZone)
  5. getCalendarDate()
  6. getCalendarDateFromToday(final int numDays)
  7. getCalendarDayString(Calendar date)
  8. getCalendarField(char c)
  9. getCalendarField(Date date, int calFieldId)