List of usage examples for java.util Calendar DATE
int DATE
To view the source code for java.util Calendar DATE.
Click Source Link
get
and set
indicating the day of the month. From source file:Main.java
/** * Gets the default ARO trace folder name in the HH:MM:SS:DD:MM:YY format. * /* ww w.ja v a2s . co m*/ * @return The default ARO trace folder name. */ public static String getDefaultTraceFolderName() { final Date systemDate = new Date(); final Calendar now = Calendar.getInstance(); final int currenthours = systemDate.getHours(); final int currentminutes = systemDate.getMinutes(); final int currentseconds = systemDate.getSeconds(); final int currentdate = now.get(Calendar.DATE); // java calendar int currentmonth = now.get(Calendar.MONTH); // As Jan is defined as 0 in currentmonth = currentmonth + 1; if (currentmonth >= 13) // As Jan is defined as 0 in java calendar currentmonth = 1; String currentMonth = Integer.toString(currentmonth); String currentDate = Integer.toString(currentdate); String currentHours = Integer.toString(currenthours); String currentMinutes = Integer.toString(currentminutes); String currentSeconds = Integer.toString(currentseconds - 1); if (currentmonth < 10) { currentMonth = ""; currentMonth = "0" + currentmonth; } if (currentdate < 10) { currentDate = ""; currentDate = "0" + currentdate; } if (currenthours < 10) { currentHours = ""; currentHours = "0" + currenthours; } if (currentminutes < 10) { currentMinutes = ""; currentMinutes = "0" + currentminutes; } if (currentseconds < 10) { currentSeconds = ""; currentSeconds = "0" + currentseconds; } final String folderName = now.get(Calendar.YEAR) + "-" + currentMonth + "-" + currentDate + "-" + currentHours + "-" + currentMinutes + "-" + currentSeconds; return folderName; }
From source file:Main.java
/** * Encode a java date/time into a 16-bit encoded DOS date * /*from w w w. j ava2 s . c om*/ * @param javaDateTime * @return long */ public static int encodeDate(long javaDateTime) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(javaDateTime); return 512 * (cal.get(Calendar.YEAR) - 1980) + 32 * (cal.get(Calendar.MONTH) + 1) + cal.get(Calendar.DATE); }
From source file:DateTimeUtil.java
/** * /* w w w . j a va 2 s. c o m*/ * @param month * @param year * @return */ public static final int getlastDateofThisMonth(int month, int year) { Calendar calendar = Calendar.getInstance(); if (year > -1) { calendar.set(Calendar.YEAR, year); } if (month > -1) { month--; calendar.set(Calendar.MONTH, month); } return calendar.getActualMaximum(Calendar.DATE); }
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:Util.java
public static byte[] packDate(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date);// w w w . j a v a 2 s.co m // Byte bits: 00000000 11111111 22222222 33333333 44444444 // Contents : 00YYYYYY YYYYYYMM MMDDDDDH HHHHMMMM MMSSSSSS byte[] bytes = new byte[5]; int s = c.get(Calendar.SECOND); int m = c.get(Calendar.MINUTE); int h = c.get(Calendar.HOUR_OF_DAY); int d = c.get(Calendar.DATE); int mm = c.get(Calendar.MONTH) + 1; int y = c.get(Calendar.YEAR); bytes[4] = (byte) ((m << 6) | s); bytes[3] = (byte) ((m >> 2) | (h << 4)); bytes[2] = (byte) ((h >> 4) | (d << 1) | (mm << 6)); bytes[1] = (byte) ((mm >> 2) | (y << 2)); bytes[0] = (byte) (y >> 6); return bytes; }
From source file:Main.java
public static String calcUntil(Calendar untilDate, String granularity) { String pattern = ""; if (granularity.equals("YYYY-MM-DDThh:mm:ssZ")) { untilDate.add(Calendar.SECOND, -1); pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'"; } else {/*w ww. j a v a 2s . c om*/ untilDate.add(Calendar.DATE, -1); pattern = "yyyy-MM-dd"; } SimpleDateFormat sdf = new SimpleDateFormat(pattern); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.format(untilDate.getTime()); }
From source file:Main.java
private static String getDayOfWeek(String format, int calendarField) { String strDate = null;// w ww . j a v a 2 s .c o m try { Calendar c = new GregorianCalendar(); SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format); int week = c.get(Calendar.DAY_OF_WEEK); if (week == calendarField) { strDate = mSimpleDateFormat.format(c.getTime()); } else { int offectDay = calendarField - week; if (calendarField == Calendar.SUNDAY) { offectDay = 7 - Math.abs(offectDay); } c.add(Calendar.DATE, offectDay); strDate = mSimpleDateFormat.format(c.getTime()); } } catch (Exception e) { e.printStackTrace(); } return strDate; }
From source file:Main.java
/** * Decode a 16-bit encoded DOS date/time into a java date/time. * //from w ww . j a v a2s. com * @param dosDate * @param dosTime * @return long */ public static long decodeDateTime(int dosDate, int dosTime) { final Calendar cal = Calendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, (dosTime & 0x1f) * 2); cal.set(Calendar.MINUTE, (dosTime >> 5) & 0x3f); cal.set(Calendar.HOUR_OF_DAY, dosTime >> 11); cal.set(Calendar.DATE, dosDate & 0x1f); cal.set(Calendar.MONTH, ((dosDate >> 5) & 0x0f) - 1); cal.set(Calendar.YEAR, 1980 + (dosDate >> 9)); return cal.getTimeInMillis(); }
From source file:com.tinypace.mobistore.util.DateUtils.java
/** * ? //from ww w. j a v a 2s .co m * * @param d * @param day * @return */ public static Date getDateAfter(Date d, int day) { Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.set(Calendar.DATE, cal.get(Calendar.DATE) + day); return cal.getTime(); }
From source file:net.seratch.taskun.util.CalendarUtil.java
public static Integer getDay(Calendar calendar) { Integer day = calendar.get(Calendar.DATE); return day; }