Java Calendar Year toStringYearMonth(Calendar calendar)

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

Description

to String Year Month

License

Open Source License

Parameter

Parameter Description
calendar a parameter

Return

String ("201301")

Declaration

public static String toStringYearMonth(Calendar calendar) 

Method Source Code

//package com.java2s;
/*/*from ww w .j  av  a 2 s  . co  m*/
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Calendar;

public class Main {
    private static final int BUDDHIST_YEAR = 543;

    /**
     * @param calendar
     * @return String ("201301")
     * @example String yearMonth = DateUtils.convertCalendarToStringyearmonth(
     * DateUtils.getCurrentDateCalendarEng() );
     */
    public static String toStringYearMonth(Calendar calendar) {
        String yyyy = String.valueOf(calendar.get(Calendar.YEAR) + BUDDHIST_YEAR);
        String mm = String.valueOf(calendar.get(Calendar.MONTH) + 1);
        if (mm.length() < 2) {
            mm = "0" + mm;
        }
        return yyyy + mm;
    }
}

Related

  1. parseCalendar(int year, int month, double day, TimeZone zone)
  2. sameYear(Calendar one, Calendar two)
  3. setCalendarFields(Calendar cal, int year, int month, int day, int hour, int minute, int second, int millis)
  4. setDate(Calendar cal, int year, int month, int day)
  5. toCalendar(int year, int month, int day, int hour, int minutes, int seconds)
  6. truncCalendarToHalfYear(Calendar c)
  7. truncCalendarToYear(Calendar c)
  8. year(Calendar calendar)
  9. year(Calendar date)