List of usage examples for java.util Date getMonth
@Deprecated public int getMonth()
From source file:Main.java
public static int milli2int(long milli) { Date date = new Date(milli); int total = 0; int year = date.getYear() - 112; int month = date.getMonth() + 1; int day = date.getDate(); int hour = date.getHours(); int minute = date.getMinutes(); int sec = date.getSeconds(); total = year << 26;/*w w w. j a va 2s . c om*/ total |= month << 22; total |= day << 17; total |= hour << 12; total |= minute << 6; total |= sec; return total; }
From source file:common.util.DateUtil.java
public static boolean isCurrentMonth(Integer month) { Date today = new Date(); System.out.println("today.getMonth() = " + today.getMonth()); return today.getMonth() == month; }
From source file:Main.java
/** * Convert a Date object in a string representing the date at readable style. *//* w ww .ja va 2 s .co m*/ public static String dateToReadableString(Date date) { if (date == null) return ""; else return ("" + (date.getYear() + 1900) + "/" + (date.getMonth() + 1) + "/" + date.getDate()); }
From source file:Main.java
/** * Get the long representation of the beginning of the current date * @return current date in system time//from w w w . j a v a 2 s .c o m */ public static long getCurrentDateStartLong() { final Date currentDate = new Date(System.currentTimeMillis()); final Date currentDateBeginning = new Date(currentDate.getYear(), currentDate.getMonth(), currentDate.getDate()); return currentDateBeginning.getTime(); }
From source file:Main.java
public static String formatDate(Date d) { // TODO let user pick date format preferences ( - or - consult system settings? ) String s = (1900 + d.getYear()) + "/" + (d.getMonth() + 1) + "/" + (d.getDate()); return s;/*from www . jav a2 s . c om*/ }
From source file:Main.java
public static boolean isToday(Date dt) { Date today = new Date(System.currentTimeMillis()); int year1 = today.getYear(); int year2 = dt.getYear(); int month1 = today.getMonth(); int month2 = dt.getMonth(); int day1 = today.getDate(); int day2 = dt.getDate(); if (year1 == year2 && month1 == month2 && day1 == day2) { return true; } else {/* www. j a v a 2s . c om*/ return false; } }
From source file:irille.pub.svr.DateUtils.java
public static Date getMonthOne(Date date) { return new Date(date.getYear(), date.getMonth(), 1); }
From source file:irille.pub.svr.DateUtils.java
public static Date getMonthBefore(Date date) { return new Date(date.getYear(), date.getMonth() - 1, date.getDate()); }
From source file:Main.java
/** * @param period : today, this_week, this_month, this_year, none * @return a date filter string for making query. e.g. date >= 2013-1-1 for this_year * return null if period is none./* ww w .j a v a2 s . com*/ */ @SuppressWarnings("deprecation") public static String getDateFilterString(String period) { if (period == null) return null; Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH) + 1; // 1 - 12 int date = calendar.get(Calendar.DATE); // 1 - 31 String dateFilterString = null; if (period.equalsIgnoreCase("today")) { dateFilterString = "date >= " + year + "-" + month + "-" + date; } else if (period.contains("week")) { int offset = calendar.get(Calendar.DAY_OF_WEEK) - calendar.getFirstDayOfWeek(); long timeInMillis = calendar.getTimeInMillis() - offset * 24 * 60 * 60 * 1000; Date firstDay = new Date(timeInMillis); dateFilterString = "date >= " + (firstDay.getYear() + 1900) + "-" + firstDay.getMonth() + "-" + firstDay.getDate(); } else if (period.contains("month")) { dateFilterString = "date >= " + year + "-" + month + "-1"; } else if (period.contains("year")) { dateFilterString = "date >= " + year + "-1-1"; } return dateFilterString; }
From source file:irille.pub.svr.DateUtils.java
public static Date getDateSub(Date date, int sub) { return new Date(date.getYear(), date.getMonth(), date.getDate() - sub); }