Java Calendar Create createDateStr(Calendar calendar)

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

Description

create Date Str

License

Open Source License

Declaration

public static String createDateStr(Calendar calendar) 

Method Source Code


//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static final String DATE_DELIMITER = "-";

    public static String createDateStr(Calendar calendar) {
        int monthInt = calendar.get(Calendar.MONTH) + 1;
        String monthStr = monthInt < 10 ? "0" + monthInt : "" + monthInt;
        int dayInt = calendar.get(Calendar.DAY_OF_MONTH);
        String dayStr = dayInt < 10 ? "0" + dayInt : "" + dayInt;
        String dateStr = calendar.get(Calendar.YEAR) + DATE_DELIMITER + monthStr + DATE_DELIMITER + dayStr;
        return dateStr;
    }/*  w w w  . ja v  a2  s . c  om*/

    public static String createDateStr(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return createDateStr(calendar);
    }
}

Related

  1. createCalendarFromParts(String[] parts)
  2. createCalendarInstance(final Locale locale)
  3. createCalendarMidnight(final Date date)
  4. createCalendarWith()
  5. createDateFormatString(Calendar cal)
  6. createIsoCalendar()
  7. createResetCalendar()
  8. createTimestampStr(Calendar para_calendar)
  9. getCalendar()