Java Calendar to String getDateString(Calendar calendar)

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

Description

get Date String

License

Open Source License

Declaration

public static String getDateString(Calendar calendar) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;

public class Main {
    public static String getDateString(Calendar calendar) {
        StringBuffer sb = new StringBuffer();
        sb.append(calendar.get(Calendar.YEAR)).append("-");
        int month = calendar.get(Calendar.MONTH) + 1;
        if (month < 10)
            sb.append("0");
        sb.append(month).append("-");
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        if (day < 10)
            sb.append("0");
        sb.append(day);/*from  w ww.ja va2 s. c  o m*/
        return sb.toString();
    }

    public static final String getDateString(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);
        return getDateString(calendar);
    }
}

Related

  1. calendarToXSDString(Calendar cal, String fmt)
  2. dateToCalendar(final String date)
  3. dateToString(Calendar date, DateFormat format)
  4. getDateString(Calendar cal)
  5. getDateString(Calendar cal)
  6. getDateToString(Calendar argCal)
  7. getString(Calendar calendar)
  8. toString(Calendar c)
  9. toString(Calendar cal)