List of usage examples for java.util Calendar setTime
public final void setTime(Date date)
Date
. From source file:Main.java
public static Date getDateTimeFrom(Date iDate, int mode, int adddate) { Calendar calendar = Calendar.getInstance(); Calendar calendarDate = Calendar.getInstance(); calendarDate.setTime(iDate); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); switch (mode) { case Calendar.DAY_OF_MONTH: { calendar.set(Calendar.DAY_OF_MONTH, calendarDate.get(Calendar.DAY_OF_MONTH) + adddate); }/*from ww w.ja va2 s . c o m*/ break; } Date ret = calendar.getTime(); Log.v("!!!!!!!!!! calendar=", "" + ret); return ret; }
From source file:com.skipjaq.awspricing.pricing.AwsPricing.java
private static Date getDate(String dateTime) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); try {/* www .j av a2s .c om*/ Date date = formatter.parse(dateTime); return date; } catch (ParseException e) { Date currentDate = new Date(); Calendar c = Calendar.getInstance(); c.setTime(currentDate); c.roll(Calendar.DAY_OF_MONTH, 1); Date yesterday = c.getTime(); System.out.println("Parse date time went wrong, getting yesterday " + yesterday); return yesterday; } }
From source file:com.liusoft.dlog4j.util.DateUtils.java
/** * ?/*w ww. jav a 2 s . co m*/ * @param date * @param time * @return */ public static Calendar mergeDateTime(Date date, Time time) { Calendar cal = Calendar.getInstance(); if (date != null) cal.setTime(date); if (time != null) { Calendar temp = Calendar.getInstance(); temp.setTime(time); cal.set(Calendar.HOUR_OF_DAY, temp.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, temp.get(Calendar.MINUTE)); cal.set(Calendar.SECOND, temp.get(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, temp.get(Calendar.MILLISECOND)); } return cal; }
From source file:Main.java
/** * Returns a ISO 8601 representation of the given date, which is * in an unknown timezone. This method is thread safe and non-blocking. * * @see <a href="https://issues.apache.org/jira/browse/TIKA-495">TIKA-495</a> * @param date given date/*w ww. j a va2 s . co m*/ * @return ISO 8601 date string, without timezone details */ public static String formatDateUnknownTimezone(Date date) { // Create the Calendar object in the system timezone Calendar calendar = GregorianCalendar.getInstance(TimeZone.getDefault(), Locale.US); calendar.setTime(date); // Have it formatted String formatted = formatDate(calendar); // Strip the timezone details before returning return formatted.substring(0, formatted.length() - 1); }
From source file:Main.java
private static Calendar cal(TimeZone tz, Date date) { Calendar cal = (tz != null) ? new GregorianCalendar(tz) : new GregorianCalendar(); cal.setTime(date); return cal;/*from w w w . ja va 2 s .c o m*/ }
From source file:DateUtils.java
public static String getTimestamp() { 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); 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 "" + year + "-" + month + "-" + day + "_" + formatTime(hours, minutes, seconds, milli); }
From source file:Main.java
/** * Get week by datetime, datetime format must be contracted with DATE_FORMAT. * * @param datetime// w w w.ja va 2s . c o m * @return */ public static String getWeek(String datetime) { Calendar cal = Calendar.getInstance(); DateFormat f = new SimpleDateFormat(DATE_FORMAT); try { cal.setTime(f.parse(datetime)); int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1; if (week_index < 0) { week_index = 0; } return WEEKS[week_index]; } catch (ParseException e) { e.printStackTrace(); } return ""; }
From source file:net.ceos.project.poi.annotated.bean.AutoResizeObjectBuilder.java
/** * Validate the AutoResizeObject based on the object build with the method * 'buildAutoResizeObject'//from w w w .ja v a2s . c o m * * @param toValidate * the object to validate */ public static void validateAutoResizeObject(AutoResizeObject toValidate) { AutoResizeObject base = buildAutoResizeObject(); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Calendar calendarUnmarshal = Calendar.getInstance(); calendarUnmarshal.setTime(toValidate.getDateAttribute()); 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.getStringAttribute(), toValidate.getStringAttribute()); assertEquals(base.getDoubleAttribute(), toValidate.getDoubleAttribute()); assertEquals(base.getLongAttribute(), toValidate.getLongAttribute()); assertEquals(base.isBooleanPrimitiveAttribute(), toValidate.isBooleanPrimitiveAttribute()); assertEquals(base.getFloatPrimitiveAttribute(), toValidate.getFloatPrimitiveAttribute()); assertEquals(base.getUnitFamily(), toValidate.getUnitFamily()); assertEquals(base.getBigDecimalAttribute(), toValidate.getBigDecimalAttribute()); // TODO add new validation below }
From source file:net.ceos.project.poi.annotated.bean.BasicObjectBuilder.java
/** * Validate the BasicObject based on the object build with the method * 'buildBasicObject'//from w w w. j a v a2s .co m * * @param toValidate * the object to validate */ public static void validateBasicObject(BasicObject toValidate) { BasicObject base = buildBasicObject(); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Calendar calendarUnmarshal = Calendar.getInstance(); calendarUnmarshal.setTime(toValidate.getDateAttribute()); 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.getStringAttribute(), toValidate.getStringAttribute()); assertEquals(base.getDoubleAttribute(), toValidate.getDoubleAttribute()); assertEquals(base.getLongAttribute(), toValidate.getLongAttribute()); assertEquals(base.isBooleanPrimitiveAttribute(), toValidate.isBooleanPrimitiveAttribute()); assertEquals(base.getFloatPrimitiveAttribute(), toValidate.getFloatPrimitiveAttribute()); assertEquals(base.getUnitFamily(), toValidate.getUnitFamily()); assertEquals(base.getBigDecimalAttribute(), toValidate.getBigDecimalAttribute()); // TODO add new validation below }
From source file:net.ceos.project.poi.annotated.bean.UniqueDecoratorObjectBuilder.java
/** * Validate the UniqueDecoratorObject based on the object build with the method * 'buildUniqueDecoratorObject'/*w ww . ja va2s . c o m*/ * * @param toValidate * the object to validate */ public static void validateUniqueDecoratorObject(UniqueDecoratorObject toValidate) { UniqueDecoratorObject base = buildUniqueDecoratorObject(); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Calendar calendarUnmarshal = Calendar.getInstance(); calendarUnmarshal.setTime(toValidate.getDateAttribute()); 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.getStringAttribute(), toValidate.getStringAttribute()); assertEquals(base.getIntegerAttribute(), toValidate.getIntegerAttribute()); assertEquals(base.getBooleanAttribute(), toValidate.getBooleanAttribute()); assertEquals(base.getDoublePrimitiveAttribute(), toValidate.getDoublePrimitiveAttribute()); assertEquals(base.getLongPrimitiveAttribute(), toValidate.getLongPrimitiveAttribute()); assertEquals(base.getFloatAttribute(), toValidate.getFloatAttribute()); assertEquals(base.getUnitFamily(), toValidate.getUnitFamily()); assertEquals(base.getBigDecimalAttribute(), toValidate.getBigDecimalAttribute()); }