List of usage examples for java.util Calendar setTime
public final void setTime(Date date)
Date
. From source file:Main.java
public static int getDay(String strDate, String format) { int day = 0;/* w w w .j a v a2s . com*/ try { Calendar c = new GregorianCalendar(); SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format); c.setTime(mSimpleDateFormat.parse(strDate)); day = c.get(Calendar.DAY_OF_MONTH); } catch (Exception e) { e.printStackTrace(); } return day; }
From source file:Main.java
public static int getMonth(String strDate, String format) { int month = 0; try {/*from w w w. j a v a 2 s. c o m*/ Calendar c = new GregorianCalendar(); SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format); c.setTime(mSimpleDateFormat.parse(strDate)); month = c.get(Calendar.MONTH) + 1; } catch (Exception e) { e.printStackTrace(); } return month; }
From source file:com.ourlife.dev.common.utils.DateUtils.java
/** * ??//w w w. j a v a 2 s .c o m * * @param date * @return */ public static String[] getDayBeginTimeAndEndTime(String date) { String[] dates = new String[2]; Date beginDate = DateUtils.parseDate(date); dates[0] = DateUtils.formatDate(beginDate, "yyyy-MM-dd HH:mm:ss"); Calendar calendar = Calendar.getInstance(); calendar.setTime(beginDate); calendar.add(Calendar.DATE, 1); dates[1] = DateUtils.formatDate(calendar.getTime(), "yyyy-MM-dd HH:mm:ss"); return dates; }
From source file:com.ourlife.dev.common.utils.DateUtils.java
/** * ??//from w w w. j av a 2 s .co m * * @param date * @return */ public static String[] getMonthBeginTimeAndEndTime(String date) { String[] dates = new String[2]; Calendar calendar = Calendar.getInstance(); calendar.setTime(DateUtils.parseDate(date)); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); dates[0] = DateUtils.formatDate(calendar.getTime(), "yyyy-MM-dd HH:mm:ss"); calendar.add(Calendar.MONTH, 1); dates[1] = DateUtils.formatDate(calendar.getTime(), "yyyy-MM-dd HH:mm:ss"); return dates; }
From source file:net.ceos.project.poi.annotated.bean.FreeElementAdvancedObjectBuilder.java
/** * Validate the FreeElementAdvancedObject based on the object build with the * method 'buildFreeElementAdvancedObject' * /*www . j a v a 2 s.co m*/ * @param toValidate * the object to validate */ public static void validateFreeElementAdvancedObject(FreeElementAdvancedObject toValidate) { FreeElementAdvancedObject base = buildFreeElementAdvancedObject(); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Calendar calendarUnmarshal = Calendar.getInstance(); calendarUnmarshal.setTime(toValidate.getFreeDate()); assertEquals(calendar.get(Calendar.YEAR), calendarUnmarshal.get(Calendar.YEAR)); assertEquals(calendar.get(Calendar.MONTH), calendarUnmarshal.get(Calendar.MONTH)); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), calendarUnmarshal.get(Calendar.DAY_OF_MONTH)); assertEquals(base.getFreeString(), toValidate.getFreeString()); assertEquals(base.getFreeDouble(), toValidate.getFreeDouble()); assertEquals(base.getFreePrimitiveInt(), toValidate.getFreePrimitiveInt()); assertEquals(base.getFreeLong(), toValidate.getFreeLong()); assertEquals(base.isFreePrimitiveBoolean(), toValidate.isFreePrimitiveBoolean()); // TODO add new validation below }
From source file:net.ceos.project.poi.annotated.bean.FreeElementObjectBuilder.java
/** * Validate the FreeElementObject based on the object build with the method * 'buildFreeElementObject'//from w w w .jav a 2 s .c om * * @param toValidate * the object to validate */ public static void validateFreeElementObject(FreeElementObject toValidate) { FreeElementObject base = buildFreeElementObject(); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Calendar calendarUnmarshal = Calendar.getInstance(); calendarUnmarshal.setTime(toValidate.getFreeDate()); assertEquals(calendar.get(Calendar.YEAR), calendarUnmarshal.get(Calendar.YEAR)); assertEquals(calendar.get(Calendar.MONTH), calendarUnmarshal.get(Calendar.MONTH)); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), calendarUnmarshal.get(Calendar.DAY_OF_MONTH)); assertEquals(base.getFreeString(), toValidate.getFreeString()); assertEquals(base.getFreeDouble(), toValidate.getFreeDouble()); assertEquals(base.getFreePrimitiveInt(), toValidate.getFreePrimitiveInt()); assertEquals(base.getFreeLong(), toValidate.getFreeLong()); assertEquals(base.isFreePrimitiveBoolean(), toValidate.isFreePrimitiveBoolean()); // TODO add new validation below }
From source file:DateUtils.java
public static String getDate() { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); return "" + year + "-" + month + "-" + day; }
From source file:Main.java
/** *Converts a dateTimeString and makes a Calendar object * @param dateTimeString in format 2012-10-15T08:17:00 * @return Calendar object/*from w w w. j a va2 s . c o m*/ * */ public static Calendar parseCalendarString(String dateTimeString) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); Date date = null; try { date = dateFormat.parse(dateTimeString); } catch (ParseException e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("Europe/Stockholm")); cal.setTime(date); return cal; }
From source file:DateUtils.java
public static String getTime() { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); int hours = cal.get(Calendar.HOUR_OF_DAY); // use 24 hour clock int minutes = cal.get(Calendar.MINUTE); int seconds = cal.get(Calendar.SECOND); int milli = cal.get(Calendar.MILLISECOND); return formatTime(hours, minutes, seconds, milli); }
From source file:net.duckling.ddl.util.EncodeUtil.java
public static String getNextThreeDay() { Calendar c = Calendar.getInstance(); c.setTime(new Date()); c.add(Calendar.DATE, 3);//from w w w . j av a 2 s . c o m return AoneTimeUtils.formatToDateTime(c.getTime()); }