Java Calendar Day getDay(Calendar cal)

Here you can find the source of getDay(Calendar cal)

Description

get Day

License

Open Source License

Declaration

public static String getDay(Calendar cal) 

Method Source Code

//package com.java2s;

import java.util.Calendar;

public class Main {

    public static String getDay(Calendar cal) {
        return strLen(String.valueOf(cal.get(Calendar.DAY_OF_MONTH)), 2);
    }//from w w  w  .ja v a2s  .c o m

    public static int getDay(String s) {
        if (s == null || s.length() < 10) {
            return 1;
        }
        return Integer.parseInt(s.substring(8, 10));
    }

    private static String strLen(String s, int len) {
        if (isNullStr(s)) {
            s = "";
        }
        if (s.length() == 8) {
            return s;
        }
        for (int i = 0; i < len - s.length(); i++) {
            s = "0" + s;
            if (s.length() == 8) {
                break;
            }
        }
        return s;
    }

    private static boolean isNullStr(String s) {
        if (s == null || s.trim().length() <= 0) {
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. getBeginDay(Calendar cal)
  2. getCanonicalDay(Calendar cal)
  3. getCanonicalDayFrom(Calendar day, int daysFrom)
  4. getCleanDay(Calendar c)
  5. getCurDay(Calendar calendar)
  6. getDay(Calendar calendar)
  7. getDay(Calendar calendar)
  8. getDayEndCalendar(Calendar cal)
  9. getDayName(Calendar cal)