List of usage examples for java.util Calendar set
public void set(int field, int value)
From source file:Main.java
public static int getDays(int year, int month) { Calendar calendar = Calendar.getInstance(); calendar.clear();//w w w .j a va 2 s. c om calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); return days; }
From source file:Main.java
public static String getDate(int hour, int min) { Date d = new Date(); Calendar now = Calendar.getInstance(); now.setTime(d);//from w w w. j a va 2s.com now.set(Calendar.HOUR, now.get(Calendar.HOUR) + hour); now.set(Calendar.MINUTE, now.get(Calendar.MINUTE) + min); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH/mm"); return sdf.format(now.getTime()); }
From source file:Main.java
public static Date getEndDateOfMonth(int year, int month) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.MONTH, month); cal.set(Calendar.YEAR, year); String enddat = year + "-" + (month + 1) + "-" + cal.getActualMaximum(Calendar.DATE); Date enddate = sdf.parse(enddat); return enddate; }
From source file:Main.java
public static Calendar getNextStart() { Calendar cc = Calendar.getInstance(); cc.roll(Calendar.HOUR, 1);// w ww .j av a2 s .c o m cc.set(Calendar.MINUTE, 0); cc.set(Calendar.SECOND, 0); return cc; }
From source file:Main.java
public static Date getStartDateOfMonth(int year, int month) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.MONTH, month); cal.set(Calendar.YEAR, year); String startdat = year + "-" + (month + 1) + "-01"; Date startdate = sdf.parse(startdat); return startdate; }
From source file:Main.java
public static Date rewindToBeginningOfMonth(Date date) { Calendar cal = buildFromDate(rewindToBeginningOfDay(date)); cal.set(Calendar.DAY_OF_MONTH, 1); return cal.getTime(); }
From source file:Main.java
public static int getFirstDayOfWeek(Date date) { int n = getDayOfWeek(date); Calendar c = Calendar.getInstance(); c.setTime(date);//from ww w. j a v a 2 s .c o m c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) - n + 1); return c.get(Calendar.DAY_OF_MONTH); }
From source file:Main.java
public static Date getFirstDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from w ww. j a v a2 s . co m*/ calendar.set(Calendar.DATE, 1); return calendar.getTime(); }
From source file:Main.java
public static long getYearStart() { Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_YEAR, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0);//from www .j a v a2 s . c om cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTimeInMillis(); }
From source file:Main.java
public static long getTimeInitializeMills(long mills) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(mills);// w w w . java2 s .c o m c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTimeInMillis(); }