java.util.Calendar Java Examples
The following examples show how to use
java.util.Calendar.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FireworksOverlay.java From Telegram-FOSS with GNU General Public License v2.0 | 7 votes |
public void start() { particles.clear(); if (Build.VERSION.SDK_INT >= 18) { setLayerType(View.LAYER_TYPE_HARDWARE, null); } started = true; startedFall = false; fallingDownCount = 0; speedCoef = 1.0f; Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); int day = calendar.get(Calendar.DAY_OF_MONTH); int month = calendar.get(Calendar.MONTH); isFebruary14 = month == 1 && (BuildVars.DEBUG_PRIVATE_VERSION || day == 14); if (isFebruary14) { loadHeartDrawables(); } for (int a = 0; a < particlesCount; a++) { particles.add(createParticle(false)); } invalidate(); }
Example #2
Source File: Revisions.java From elepy with Apache License 2.0 | 7 votes |
public void createRevision(String revisionName, RevisionType revisionType, String userId, String schemaPath, Object snapshot) throws JsonProcessingException { final var revision = new Revision(); revision.setSchemaPath(schemaPath); revision.setUserId(userId); revision.setRevisionType(revisionType); revision.setRevisionName(revisionName); revision.setRecordSnapshot(objectMapper.writeValueAsString(snapshot)); revision.setRevisionNumber(0); revision.setTimestamp(Calendar.getInstance().getTime()); }
Example #3
Source File: Utils.java From BotLibre with Eclipse Public License 1.0 | 7 votes |
public static String displayDate(Date date) { if (date == null) { return ""; } StringWriter writer = new StringWriter(); Calendar today = Calendar.getInstance(); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { writer.write("Today"); } else if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) && calendar.get(Calendar.DAY_OF_YEAR) == (today.get(Calendar.DAY_OF_YEAR) - 1)) { writer.write("Yesterday"); } else { writer.write(calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US)); writer.write(" "); writer.write(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))); if (calendar.get(Calendar.YEAR) != today.get(Calendar.YEAR)) { writer.write(" "); writer.write(String.valueOf(calendar.get(Calendar.YEAR))); } } return writer.toString(); }
Example #4
Source File: TimeUtil.java From youqu_master with Apache License 2.0 | 7 votes |
/** * 描述:获取本周的某一天. * * @param format the format * @param calendarField the calendar field * @return String String类型日期时间 */ private static String getDayOfWeek(String format, int calendarField) { String strDate = null; 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; }
Example #5
Source File: DateTimeUtils.java From opencps-v2 with GNU Affero General Public License v3.0 | 7 votes |
public static int getDayFromDate(Date date) { int day = 0; if (date != null) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); day += calendar.get(Calendar.DAY_OF_MONTH); // calendar.setTime(date); // day = calendar.get(Calendar.DAY_OF_MONTH); // return day; } else { day += 1; } return day; }
Example #6
Source File: DateTimeUtil.java From opencps-v2 with GNU Affero General Public License v3.0 | 7 votes |
public static int getMonthFromDate(Date date) { int month = 0; if (date != null) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); month += calendar.get(Calendar.MONTH); // calendar.setTime(date); // month = calendar.get(Calendar.MONTH); // return month; } else { month += 1; } return month; }
Example #7
Source File: DateUtil.java From fabric-net-server with Apache License 2.0 | 7 votes |
/** * 返回日期中的指定部分--YYYY 年份,MM 月份,DD 天,HH 小时 MI 分 SS 秒 * * @param date * date日期 * @param type * 日期中的指定部分 * * @return 日期中的指定部分值 */ public int getDatePart(Date date, DatePartType type) { Calendar cal = Calendar.getInstance(); cal.setTime(date); switch (type) { case Year: return cal.get(Calendar.YEAR); case Month: return cal.get(Calendar.MONTH); case Day: return cal.get(Calendar.DAY_OF_MONTH); case Hour: return cal.get(Calendar.HOUR_OF_DAY); case Minute: return cal.get(Calendar.MINUTE); case Second: return cal.get(Calendar.SECOND); default: return 0; } }
Example #8
Source File: DateUtilsRoundingTest.java From astor with GNU General Public License v2.0 | 7 votes |
/** * Tests DateUtils.round()-method with Calendar.DATE * Includes rounding the extremes of one day * Includes rounding to January 1 * * @throws Exception * @since 3.0 */ public void testRoundDate() throws Exception { final int calendarField = Calendar.DATE; Date roundedUpDate, roundedDownDate, lastRoundedDownDate; Date minDate, maxDate; roundedUpDate = dateTimeParser.parse("June 2, 2008 0:00:00.000"); roundedDownDate = targetDateDate; lastRoundedDownDate = dateTimeParser.parse("June 1, 2008 11:59:59.999"); baseRoundTest(roundedUpDate, roundedDownDate, lastRoundedDownDate, calendarField); //round to January 1 minDate = dateTimeParser.parse("December 31, 2007 12:00:00.000"); maxDate = dateTimeParser.parse("January 1, 2008 11:59:59.999"); roundToJanuaryFirst(minDate, maxDate, calendarField); }
Example #9
Source File: DateTimeWheelDialog.java From WheelViewDemo with Apache License 2.0 | 7 votes |
private void initAreaDate() { int startYear = startCalendar.get(Calendar.YEAR); int endYear = endCalendar.get(Calendar.YEAR); int startMonth = startCalendar.get(Calendar.MONTH) + 1; int startDay = startCalendar.get(Calendar.DAY_OF_MONTH); int startHour = startCalendar.get(Calendar.HOUR_OF_DAY); int startMinute = startCalendar.get(Calendar.MINUTE); yearItems = updateItems(DateItem.TYPE_YEAR, startYear, endYear); monthItems = updateItems(DateItem.TYPE_MONTH, startMonth, MAX_MONTH); int dayActualMaximum = startCalendar.getActualMaximum(Calendar.DAY_OF_MONTH); dayItems = updateItems(DateItem.TYPE_DAY, startDay, dayActualMaximum); hourItems = updateItems(DateItem.TYPE_HOUR, startHour, MAX_HOUR); minuteItems = updateItems(DateItem.TYPE_MINUTE, startMinute, MAX_MINUTE); yearWheelItemView.setItems(yearItems); monthWheelItemView.setItems(monthItems); dayWheelItemView.setItems(dayItems); hourWheelItemView.setItems(hourItems); minuteWheelItemView.setItems(minuteItems); }
Example #10
Source File: FormElementPickerTimeViewHolder.java From FormMaster with Apache License 2.0 | 7 votes |
@Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { mCalendarCurrentTime.set(Calendar.HOUR_OF_DAY, hourOfDay); mCalendarCurrentTime.set(Calendar.MINUTE, minute); String myFormatTime = ((FormElementPickerTime) mFormElement).getTimeFormat(); // custom format SimpleDateFormat sdfTime = new SimpleDateFormat(myFormatTime, Locale.US); String currentValue = mFormElement.getValue(); String newValue = sdfTime.format(mCalendarCurrentTime.getTime()); // trigger event only if the value is changed if (!currentValue.equals(newValue)) { mReloadListener.updateValue(mPosition, newValue); } }
Example #11
Source File: RelativeTimeFormatterTest.java From jsmpp with Apache License 2.0 | 6 votes |
@Test(groups = "checkintest") public void formatRelativeTimeHours() { GregorianCalendar smscDate = new GregorianCalendar(TimeZone.getTimeZone("America/Denver")); GregorianCalendar date = new GregorianCalendar(TimeZone.getTimeZone("America/Denver")); date.setTimeInMillis(smscDate.getTimeInMillis()); date.add(Calendar.HOUR_OF_DAY, 16); assertEquals(relativeTimeFormatter.format(date, smscDate), "000000160000000R"); }
Example #12
Source File: PaymentServiceProviderBeanTest.java From development with Apache License 2.0 | 6 votes |
private ChargingData createChargingData() throws Exception { ChargingData chargingData = new ChargingData(); chargingData.setTransactionId(1L); chargingData.setAddress(""); chargingData.setCurrency("EUR"); chargingData.setCustomerKey(Long.valueOf(1L)); chargingData.setEmail("email"); chargingData.setExternalIdentifier("externalidentifier"); Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, 1970); c.set(Calendar.MONTH, 0); c.set(Calendar.DAY_OF_MONTH, 2); chargingData.setPeriodEndTime(c.getTime()); chargingData.setPeriodStartTime(c.getTime()); chargingData.setSellerKey(Long.valueOf(2L)); chargingData.setGrossAmount(BigDecimal.valueOf(1226)); chargingData.setNetAmount(BigDecimal.valueOf(1030)); chargingData.setNetDiscount(BigDecimal.ZERO); chargingData.setVatAmount(BigDecimal.valueOf(196)); chargingData.setVat(""); chargingData.setSubscriptionId("sub"); chargingData.setPon("12345"); chargingData.getPriceModelData().add( new PriceModelData(1, 1259622000000L, 1262300400000L, BigDecimal.valueOf(1000))); chargingData.getPriceModelData().add( new PriceModelData(2, 1259622000000L, 1262300400000L, BigDecimal.valueOf(2000))); return chargingData; }
Example #13
Source File: Astro.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
@ActionDoc(text = "Returns the sunset end for the given date and coordinates") public static Calendar getAstroSunsetEnd( @ParamDoc(name = "date", text = "The date to calculate the sunset") Date date, @ParamDoc(name = "latitude", text = "The latitude") double latitude, @ParamDoc(name = "longitude", text = "The longitude") double longitude) { return getSun(date, latitude, longitude).getSet().getEnd(); }
Example #14
Source File: ExtDateTimeUtils.java From ade with GNU General Public License v3.0 | 5 votes |
/** * Method to return a Date instance which is exactly numDays * days before the point in time designated by the input Date. * * @param dateInst - instance of Date * @param numDays - positive integer * @return - instance of Date as described */ public static Date daysBefore(Date dateInst, int numDays) { if ((numDays <= 0) || (dateInst == null)) { throw new IllegalArgumentException(); } final Calendar cal = new GregorianCalendar(); cal.setTime(dateInst); cal.add(Calendar.DAY_OF_YEAR, -numDays); return cal.getTime(); }
Example #15
Source File: VideoOnDemand.java From Pocket-Plays-for-Twitch with GNU General Public License v3.0 | 5 votes |
private void setRecordedAtDate(String recordedAtString) { try { DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); this.recordedAt = Calendar.getInstance(); this.recordedAt.setTime(formatter.parse(recordedAtString.split("T")[0])); } catch (ParseException e) { e.printStackTrace(); } }
Example #16
Source File: Spider.java From JavaMainRepo with Apache License 2.0 | 5 votes |
@Override public double getPredisposition() throws Exception { Calendar date = GregorianCalendar.getInstance(); if (date.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) { return 0.3; } else { return 0; } }
Example #17
Source File: TaskCheckExecutor.java From scava with Eclipse Public License 2.0 | 5 votes |
public Date dateToDay(Date date) { Calendar cal = Calendar.getInstance(); // locale-specific cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return new Date(cal.getTimeInMillis()); }
Example #18
Source File: AntlrParserConversionTest.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
@Test public void dateParseLocNominal() { try { Locale locale = new Locale("en"); Date date = new Date(707781600000L); Calendar cal = Calendar.getInstance(locale); cal.setTime(date); Expression expression = getExpressionWithFunctionContext("date_parse_loc(\"6/6/92\", \"en\")"); assertEquals(ExpressionType.DATE, expression.getExpressionType()); assertEquals(cal.getTime(), expression.evaluateDate()); } catch (ExpressionException e) { fail(e.getMessage()); } }
Example #19
Source File: SunriseSunset.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
/** * @param calendar the datetime for which to determine if it's astronomical twilight in the given location * @param latitude the latitude of the location in degrees. * @param longitude the longitude of the location in degrees (West is negative) * @return true if it is astronomical twilight at the given location and the given calendar. * This returns true if the given time at the location is between nautical and astronomical twilight dusk * or between astronomical and nautical twilight dawn. */ public static boolean isAstronomicalTwilight(Calendar calendar, double latitude, double longitude) { Calendar[] nauticalTwilight = getNauticalTwilight(calendar, latitude, longitude); if (nauticalTwilight == null) return false; Calendar[] astronomicalTwilight = getAstronomicalTwilight(calendar, latitude, longitude); if (astronomicalTwilight == null) return false; return (calendar.after(nauticalTwilight[1]) && calendar.before(astronomicalTwilight[1]) || (calendar.after(astronomicalTwilight[0]) && calendar.before(nauticalTwilight[0]))); }
Example #20
Source File: OrderDetails.java From MagicPrint-ECommerce-App-Android with MIT License | 5 votes |
private void productdetails() { Bundle bundle = getIntent().getExtras(); //setting total price totalAmount.setText(bundle.get("totalprice").toString()); //setting number of products noOfItems.setText(bundle.get("totalproducts").toString()); cartcollect = (ArrayList<SingleProductModel>) bundle.get("cartproducts"); //delivery date SimpleDateFormat formattedDate = new SimpleDateFormat("dd/MM/yyyy"); Calendar c = Calendar.getInstance(); c.add(Calendar.DATE, 7); // number of days to add String tomorrow = (formattedDate.format(c.getTime())); deliveryDate.setText(tomorrow); mainActivityMultiLineRadioGroup.setOnCheckedChangeListener(new MultiLineRadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(ViewGroup group, RadioButton button) { payment_mode=button.getText().toString(); } }); user = session.getUserDetails(); placed_user_name=user.get(UserSession.KEY_NAME); getPlaced_user_email=user.get(UserSession.KEY_EMAIL); getPlaced_user_mobile_no=user.get(UserSession.KEY_MOBiLE); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy-HH-mm"); currdatetime = sdf.format(new Date()); }
Example #21
Source File: FastDateFormat.java From lams with GNU General Public License v2.0 | 5 votes |
/** * <p>Formats a <code>Date</code>, <code>Calendar</code> or * <code>Long</code> (milliseconds) object.</p> * * @param obj the object to format * @param toAppendTo the buffer to append to * @param pos the position - ignored * @return the buffer passed in */ public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { if (obj instanceof Date) { return format((Date) obj, toAppendTo); } else if (obj instanceof Calendar) { return format((Calendar) obj, toAppendTo); } else if (obj instanceof Long) { return format(((Long) obj).longValue(), toAppendTo); } else { throw new IllegalArgumentException("Unknown class: " + (obj == null ? "<null>" : obj.getClass().getName())); } }
Example #22
Source File: JdbcEventDao.java From Spring-Security-Third-Edition with MIT License | 5 votes |
@Override public int createEvent(final Event event) { if (event == null) { throw new IllegalArgumentException("event cannot be null"); } if (event.getId() != null) { throw new IllegalArgumentException("event.getId() must be null when creating a new Message"); } final CalendarUser owner = event.getOwner(); if (owner == null) { throw new IllegalArgumentException("event.getOwner() cannot be null"); } final CalendarUser attendee = event.getAttendee(); if (attendee == null) { throw new IllegalArgumentException("attendee.getOwner() cannot be null"); } final Calendar when = event.getWhen(); if(when == null) { throw new IllegalArgumentException("event.getWhen() cannot be null"); } KeyHolder keyHolder = new GeneratedKeyHolder(); this.jdbcOperations.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement( "insert into events (when,summary,description,owner,attendee) values (?, ?, ?, ?, ?)", new String[] { "id" }); ps.setDate(1, new java.sql.Date(when.getTimeInMillis())); ps.setString(2, event.getSummary()); ps.setString(3, event.getDescription()); ps.setInt(4, owner.getId()); ps.setObject(5, attendee == null ? null : attendee.getId()); return ps; } }, keyHolder); return keyHolder.getKey().intValue(); }
Example #23
Source File: TestLocalDate_Constructors.java From astor with GNU General Public License v2.0 | 5 votes |
public void testFactory_fromDateFields_beforeYearZero3() throws Exception { GregorianCalendar cal = new GregorianCalendar(3, 1, 3, 4, 5, 6); cal.set(Calendar.ERA, GregorianCalendar.BC); cal.set(Calendar.MILLISECOND, 7); LocalDate expected = new LocalDate(-2, 2, 3); assertEquals(expected, LocalDate.fromDateFields(cal.getTime())); }
Example #24
Source File: DateUtils.java From roncoo-pay with Apache License 2.0 | 5 votes |
/** * 上月最后一天 * * @return */ public static Date getPreviousMonthLastDay() { Calendar lastDate = Calendar.getInstance(); lastDate.set(Calendar.DATE, 1);// 设为当前月的1号 lastDate.add(Calendar.DATE, -1); return getMinTime(lastDate.getTime()); }
Example #25
Source File: FastDatePrinterTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testLang303() { final Calendar cal = Calendar.getInstance(); cal.set(2004, 11, 31); DatePrinter format = getInstance(YYYY_MM_DD); final String output = format.format(cal); format = SerializationUtils.deserialize(SerializationUtils.serialize((Serializable) format)); assertEquals(output, format.format(cal)); }
Example #26
Source File: TimeMessage.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public byte[] getTimeMessage( long timestamp) { init(11); //timestamp = 587030940; final Calendar c = Calendar.getInstance(); c.setTimeInMillis(timestamp); putData(calendarToRawBytes(c)); putData((byte) 0x01); //adjust reason (manual time update) //constant putData((byte) 0x0C); return getBytes(); }
Example #27
Source File: CalendarHelper.java From flow-android with MIT License | 5 votes |
public static Calendar getCurrentWeek() { Calendar currentWeek = Calendar.getInstance(); currentWeek.setFirstDayOfWeek(Calendar.MONDAY); currentWeek.set(Calendar.HOUR_OF_DAY, 0); currentWeek.clear(Calendar.MINUTE); currentWeek.clear(Calendar.SECOND); currentWeek.clear(Calendar.MILLISECOND); return currentWeek; }
Example #28
Source File: RexBuilderTest.java From Quicksql with MIT License | 5 votes |
private void checkDate(RexNode node) { assertThat(node.toString(), is("1969-07-21")); RexLiteral literal = (RexLiteral) node; assertThat(literal.getValue() instanceof Calendar, is(true)); assertThat(literal.getValue2() instanceof Integer, is(true)); assertThat(literal.getValue3() instanceof Integer, is(true)); assertThat((Integer) literal.getValue2(), is(MOON_DAY)); assertThat(literal.getValueAs(Calendar.class), notNullValue()); assertThat(literal.getValueAs(DateString.class), notNullValue()); }
Example #29
Source File: StringAndDateConvertor.java From tddl with Apache License 2.0 | 5 votes |
@Override public Object convert(Object src, Class destClass) { if (String.class.isInstance(src)) { // 必须是字符串 Date dest = (Date) super.convert(src, Date.class); Calendar result = new GregorianCalendar(); result.setTime(dest); return result; } throw new ConvertorException("Unsupported convert: [" + src + "," + destClass.getName() + "]"); }
Example #30
Source File: FTPTimestampParserImpl.java From Aria with Apache License 2.0 | 5 votes |
private static void setPrecision(int index, Calendar working) { if (index <= 0) { // e.g. MILLISECONDS return; } final int field = CALENDAR_UNITS[index - 1]; // Just in case the analysis is wrong, stop clearing if // field value is not the default. final int value = working.get(field); if (value != 0) { // don't reset if it has a value // new Throwable("Unexpected value "+value).printStackTrace(); // DEBUG } else { working.clear(field); // reset just the required field } }