List of usage examples for java.util Calendar MONTH
int MONTH
To view the source code for java.util Calendar MONTH.
Click Source Link
get
and set
indicating the month. From source file:Main.java
public static String getMonthName(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);/*w w w . ja v a 2s. co m*/ LocalDate localDate = LocalDate.of(0, cal.get(Calendar.MONTH) + 1, 1); return localDate.getMonth().name(); }
From source file:Main.java
public static int getMonthFromDate(Date date) { helperCalendar.setTime(date); return helperCalendar.get(Calendar.MONTH); }
From source file:Main.java
public static Calendar getTodayAt(int hours, int minutes) { Calendar today = Calendar.getInstance(); Calendar cal = Calendar.getInstance(); cal.clear();//from ww w . jav a2 s .c om int year = today.get(Calendar.YEAR); int month = today.get(Calendar.MONTH); //represents the day of the month int day = today.get(Calendar.DATE); cal.set(year, month, day, hours, minutes, 0); return cal; }
From source file:Main.java
public static boolean isBefore(Calendar currentCalendar, Calendar max) { int currentYear = currentCalendar.get(Calendar.YEAR); int currentMonth = currentCalendar.get(Calendar.MONTH); int currentDay = currentCalendar.get(Calendar.DAY_OF_MONTH); int maxYear = max.get(Calendar.YEAR); int maxMonth = max.get(Calendar.MONTH); int maxDay = max.get(Calendar.DAY_OF_MONTH); Log.i("TAG",// ww w . j ava 2s . c om (currentYear <= maxYear && currentMonth <= maxMonth && currentDay <= maxDay) + "currentYear" + currentYear + "maxYear" + maxYear + "currentMonth" + currentMonth + "maxMonth" + maxMonth + "currentDay" + currentDay + "maxDay" + maxDay); return (currentYear == maxYear) ? ((currentMonth == currentMonth) ? (currentDay < maxDay) : (currentMonth < maxMonth)) : (currentYear < maxYear); }
From source file:Main.java
public static Calendar getTomorrowAt(int hours, int minutes) { Calendar today = Calendar.getInstance(); Calendar cal = Calendar.getInstance(); cal.clear();// w ww .j ava 2 s. c o m int year = today.get(Calendar.YEAR); int month = today.get(Calendar.MONTH); //represents the day of the month today.add(Calendar.DATE, 1); int day = today.get(Calendar.DATE); cal.set(year, month, day, hours, minutes, 0); return cal; }
From source file:Main.java
public static String getTodayYYYYMMDD() { Calendar calendar = Calendar.getInstance(); StringBuffer sbDate = new StringBuffer(); int nYear, nMonth, nDay; nYear = calendar.get(Calendar.YEAR); nMonth = calendar.get(Calendar.MONTH) + 1; nDay = calendar.get(Calendar.DAY_OF_MONTH); sbDate.append(nYear);//from w w w .java2 s.c o m if (nMonth < 10) sbDate.append("0"); sbDate.append(nMonth); if (nDay < 10) sbDate.append("0"); sbDate.append(nDay); return sbDate.toString(); }
From source file:Main.java
public static String getCurrentTime() { DecimalFormat df = new DecimalFormat("00"); Calendar c = Calendar.getInstance(); String currentTime = c.get(Calendar.YEAR)// + "-" + df.format((c.get(Calendar.MONTH) + 1)) // + "-" + df.format(c.get(Calendar.DAY_OF_MONTH))// + "-" + df.format(c.get(Calendar.HOUR_OF_DAY)) // + "-" + df.format(c.get(Calendar.MINUTE))// + "-" + df.format(c.get(Calendar.SECOND)); return currentTime; }
From source file:Main.java
public static java.util.Date getDateEnd(java.util.Date d) { Calendar c = Calendar.getInstance(); c.clear();// w ww . j a v a 2s . co m Calendar co = Calendar.getInstance(); co.setTime(d); c.set(Calendar.DAY_OF_MONTH, co.get(Calendar.DAY_OF_MONTH)); c.set(Calendar.MONTH, co.get(Calendar.MONTH)); c.set(Calendar.YEAR, co.get(Calendar.YEAR)); c.add(Calendar.DAY_OF_MONTH, 1); c.add(Calendar.MILLISECOND, -1); return c.getTime(); }
From source file:Main.java
static float getDatePlg() { Calendar c = new GregorianCalendar(); int y = c.get(Calendar.YEAR); int m = 1 + c.get(Calendar.MONTH); int d = c.get(Calendar.DAY_OF_MONTH); return getDatePlg(y, m, d); }
From source file:Main.java
/** * Returns current date-time in format of yyyy-MM-dd hh:mm:ss * //from w w w. j a v a 2s. c o m * @return date time in string. */ public static String getCurrentTime() { int yyyy = Calendar.getInstance().get(Calendar.YEAR); int MM = Calendar.getInstance().get(Calendar.MONTH) + 1; int dd = Calendar.getInstance().get(Calendar.DATE); int hh = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); int mm = Calendar.getInstance().get(Calendar.MINUTE); int ss = Calendar.getInstance().get(Calendar.SECOND); String curDate = String.format("%04d-%02d-%02d %02d:%02d:%02d", yyyy, MM, dd, hh, mm, ss); return curDate; }