Java Calendar Day getDayStringByCalendar(Calendar calendar)

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

Description

get Day String By Calendar

License

Apache License

Declaration

public static String getDayStringByCalendar(Calendar calendar) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;

public class Main {
    public static String getDayStringByCalendar(Calendar calendar) {
        int m = calendar.get(Calendar.MONTH) + 1;
        String month = "";

        if (m >= 10)
            month = "" + m;
        else//from w  ww.j  a  v a  2  s .co m
            month = "0" + m;

        int d = calendar.get(Calendar.DAY_OF_MONTH);
        String day = "";
        if (d >= 10)
            day += d;
        else
            day = "0" + d;

        String s = calendar.get(Calendar.YEAR) + month + day;
        return s;
    }

    public static String getDayStringByCalendar(Long timeMillis) {
        if (timeMillis == 0) {
            return "19800000";
        }

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(timeMillis);
        int m = calendar.get(Calendar.MONTH) + 1;
        String month = "";

        if (m >= 10)
            month = "" + m;
        else
            month = "0" + m;

        int d = calendar.get(Calendar.DAY_OF_MONTH);
        String day = "";
        if (d >= 10)
            day += d;
        else
            day = "0" + d;

        String s = calendar.get(Calendar.YEAR) + month + day;
        return s;
    }
}

Related

  1. getDayName(Calendar cal)
  2. getDayOfPeriod(Calendar cal, long timems)
  3. getDaysFromThen(Calendar aDate)
  4. getDayStr(Calendar cal)
  5. getDayString(Calendar cal1)
  6. getEndDay(Calendar cal)
  7. getEndOfDay(Calendar c)
  8. getEndOfDay(Date date, Calendar cal)
  9. getEndOfTodayAsCalendar()