Java Code Examples for java.util.Date#setDate()
The following examples show how to use
java.util.Date#setDate() .
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: DateTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * java.util.Date#setDate(int) */ public void test_setDateI() { // Test for method void java.util.Date.setDate(int) Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9) .getTime(); d.setDate(23); assertEquals("Set incorrect date", 23, d.getDate()); }
Example 2
Source File: SportDay.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
public String formatStringDay() { Date date = new Date(); date.setYear(-1900 + year); date.setMonth(mon); date.setDate(day); return (new SimpleDateFormat(BraceletApp.getContext().getString(0x7f0d0055))).format(date); }
Example 3
Source File: DateTypeAdapter.java From doov with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("deprecation") public Object fromString(FieldInfo info, String value) { int year = Integer.parseInt(value.substring(0, 4)); int month = Integer.parseInt(value.substring(4, 6)); int day = Integer.parseInt(value.substring(6, 8)); Date date = new Date(); date.setDate(day); date.setMonth(month - 1); date.setYear(year - 1900); date.setHours(0); date.setMinutes(0); date.setSeconds(0); return date; }
Example 4
Source File: cg.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
protected String a(SportDay sportday) { Date date = new Date(); SimpleDateFormat simpledateformat = new SimpleDateFormat(); if (sportday.equals(StatisticFragment.C(q))) { return s; } if (sportday.offsetDay(StatisticFragment.C(q)) == -1 && !StatisticFragment.D(q)) { return t; } if (1 + sportday.mon == 1 && sportday.day == 1) { date.setYear(sportday.year); date.setMonth(sportday.mon); date.setDate(sportday.day); simpledateformat.applyPattern(v); } else { date.setMonth(sportday.mon); date.setDate(sportday.day); simpledateformat.applyPattern(u); } return simpledateformat.format(date); }
Example 5
Source File: StatisticDailyFragment.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
protected String formatDate(SportDay sportday) { if (sportday.equals(mToday)) { return getString(0x7f0d01b9); } if (sportday.addDay(1).equals(mToday) && !Locale.getDefault().toString().startsWith(Locale.ENGLISH.toString())) { return getString(0x7f0d005e); } else { SimpleDateFormat simpledateformat = new SimpleDateFormat(getString(0x7f0d0055)); Date date = new Date(); date.setMonth(sportday.mon); date.setDate(sportday.day); String s = simpledateformat.format(date); Object aobj[] = new Object[2]; aobj[0] = s; aobj[1] = b[sportday.getWeek()]; return getString(0x7f0d0057, aobj); } }
Example 6
Source File: WeatherAdapter.java From MuslimMateAndroid with GNU General Public License v3.0 | 6 votes |
@Override public void onBindViewHolder(ViewHolder holder, int position) { Weather weather = weatherList.get(position); String[] time = weather.dayName.split(" "); String[] weatherTime = time[1].split(":"); String[] date = time[0].split("-"); SimpleDateFormat sdf = new SimpleDateFormat("EEEE"); Date d = new Date(); d.setYear(Integer.parseInt(date[0])); d.setMonth(Integer.parseInt(date[1]) - 1); d.setDate(Integer.parseInt(date[2]) - 1); String dayOfTheWeek = sdf.format(d); Log.d("DAY", weather.dayName + " : " + dayOfTheWeek); holder.dayName.setText(NumbersLocal.convertNumberType(context, weatherTime[0] + ":" + weatherTime[1] + "")); holder.weather.setText(NumbersLocal.convertNumberType(context, weather.tempMini + "°")); holder.image.setImageResource(WeatherIcon.get_icon_id_white(weather.image)); }
Example 7
Source File: SmsParser.java From sms-ticket with Apache License 2.0 | 5 votes |
private Date parseDate(String text, String datePattern, SimpleDateFormat sdf, SimpleDateFormat sdfTime, Ticket ticket) { Matcher m = Pattern.compile(datePattern).matcher(text); if (m.find()) { String d = m.group(1); if (!isEmpty(d)) { d = d.replaceAll(";", ""); for (int i = 0; i < 2; i++) { final Date date; try { if (i == 0) { date = sdf.parse(d); // full date/time } else if (i == 1 && sdfTime != null) { date = sdfTime.parse(d); // only time } else { break; } } catch (Exception e) { continue; } if (i == 1 && ticket != null && ticket.validFrom != null) { final Date prevDate = ticket.validFrom; date.setYear(prevDate.getYear()); date.setMonth(prevDate.getMonth()); date.setDate(prevDate.getDate()); } return date; } } } throw new RuntimeException("Cannot parse date from the message " + text); }
Example 8
Source File: SingleDateSelector.java From unitime with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") public void addDays(int days) { Date d = getValue(); if (d == null) { setDate(new Date()); } else { d.setDate(d.getDate() + days); setDate(d); } }
Example 9
Source File: KChartAdapter.java From KChartView with Apache License 2.0 | 5 votes |
@Override public Date getDate(int position) { try { String s = datas.get(position).Date; String[] split = s.split("/"); Date date = new Date(); date.setYear(Integer.parseInt(split[0]) - 1900); date.setMonth(Integer.parseInt(split[1]) - 1); date.setDate(Integer.parseInt(split[2])); return date; } catch (Exception e) { e.printStackTrace(); } return null; }
Example 10
Source File: DateUtils.java From roncoo-pay with Apache License 2.0 | 5 votes |
/** * 月的最后一天 * * @param date * @return */ @SuppressWarnings("deprecation") public static Date getLastDayOfMonth(Date date) { Calendar cDay1 = Calendar.getInstance(); cDay1.setTime(date); int lastDay = cDay1.getActualMaximum(Calendar.DAY_OF_MONTH); Date lastDate = cDay1.getTime(); lastDate.setDate(lastDay); return lastDate; }
Example 11
Source File: AlbianDateTime.java From Albianj2 with BSD 3-Clause "New" or "Revised" License | 5 votes |
@SuppressWarnings("deprecation") public static Date dateAddSeconds(int year, int month, int day, long second) { Date dt = new Date(); dt.setYear(year - 1900); dt.setMonth(month - 1); dt.setDate(day); dt.setHours(0); dt.setMinutes(0); dt.setSeconds(0); Calendar rightNow = Calendar.getInstance(); rightNow.setTime(dt); rightNow.add(Calendar.SECOND, (int) second); Date dt1 = rightNow.getTime(); return dt1; }
Example 12
Source File: DateUtils.java From mumu with Apache License 2.0 | 5 votes |
/** * 月的最后一天 * * @param date * @return */ @SuppressWarnings("deprecation") public static Date getLastDayOfMonth(Date date) { Calendar cDay1 = Calendar.getInstance(); cDay1.setTime(date); int lastDay = cDay1.getActualMaximum(Calendar.DAY_OF_MONTH); Date lastDate = cDay1.getTime(); lastDate.setDate(lastDay); return lastDate; }
Example 13
Source File: DataSharingUsageStatisticsReportingServiceTest.java From gocd with Apache License 2.0 | 5 votes |
@Test public void shouldDisallowReportingDataSharingIfReportingIsInProgress() { Date lastReportedAt = new Date(); lastReportedAt.setDate(lastReportedAt.getDate() - 1); UsageStatisticsReporting existingMetric = new UsageStatisticsReporting("server-id", lastReportedAt); when(usageStatisticsReportingSqlMapDao.load()).thenReturn(existingMetric); UsageStatisticsReporting statisticsReporting = service.get(); assertTrue(statisticsReporting.canReport()); HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); service.startReporting(result); assertTrue(result.isSuccessful()); statisticsReporting = service.get(); assertFalse(statisticsReporting.canReport()); }
Example 14
Source File: TimeNowEL.java From datacollector with Apache License 2.0 | 5 votes |
@ElFunction(prefix = TIME_CONTEXT_VAR, name = "trimDate", description = "Set date portion of datetime expression to January 1, 1970") @SuppressWarnings("deprecation") public static Date trimDate(@ElParam("datetime") Date in) { if(in == null) { return null; } Date ret = new Date(in.getTime()); ret.setYear(70); ret.setMonth(0); ret.setDate(1); return ret; }
Example 15
Source File: ResidentialSite.java From refactoring-kata with MIT License | 5 votes |
public Dollars charge() { // find last reading int i = 0; while (readings[i] != null) i++; int usage = readings[i - 1].getAmount() - readings[i - 2].getAmount(); Date end = readings[i - 1].getDate(); Date start = readings[i - 2].getDate(); start.setDate(start.getDate() + 1); //set to begining of period return charge(usage, start, end); }
Example 16
Source File: SingleDateSelector.java From unitime with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") static int dayOfYear(int year, int month, int day) { Date d = new Date(year - 1900, month - 1, day); int doy = 0, y = d.getYear(); while (d.getYear() == y) { d.setDate(d.getDate() - 1); doy ++; } return doy; }
Example 17
Source File: ClientIntervalBuilderDynamicDate.java From dashbuilder with Apache License 2.0 | 5 votes |
protected Date firstIntervalDate(DateIntervalType intervalType, Date minDate, ColumnGroup columnGroup) { Date intervalMinDate = new Date(minDate.getTime()); if (YEAR.equals(intervalType)) { intervalMinDate.setMonth(0); intervalMinDate.setDate(1); intervalMinDate.setHours(0); intervalMinDate.setMinutes(0); intervalMinDate.setSeconds(0); } if (QUARTER.equals(intervalType)) { int currentMonth = intervalMinDate.getMonth(); int firstMonthYear = columnGroup.getFirstMonthOfYear().getIndex(); int rest = Quarter.getPositionInQuarter(firstMonthYear, currentMonth + 1); intervalMinDate.setMonth(currentMonth - rest); intervalMinDate.setDate(1); intervalMinDate.setHours(0); intervalMinDate.setMinutes(0); intervalMinDate.setSeconds(0); } if (MONTH.equals(intervalType)) { intervalMinDate.setDate(1); intervalMinDate.setHours(0); intervalMinDate.setMinutes(0); intervalMinDate.setSeconds(0); } if (DAY.equals(intervalType) || DAY_OF_WEEK.equals(intervalType) || WEEK.equals(intervalType)) { intervalMinDate.setHours(0); intervalMinDate.setMinutes(0); intervalMinDate.setSeconds(0); } if (HOUR.equals(intervalType)) { intervalMinDate.setMinutes(0); intervalMinDate.setSeconds(0); } if (MINUTE.equals(intervalType)) { intervalMinDate.setSeconds(0); } return intervalMinDate; }
Example 18
Source File: ExportTimetablePDF.java From unitime with Apache License 2.0 | 4 votes |
@SuppressWarnings("deprecation") protected static Date getDate(Date firstDate, int date) { Date ret = new Date(firstDate.getTime()); ret.setDate(ret.getDate() + date); return ret; }
Example 19
Source File: AdminController.java From MOOC with MIT License | 4 votes |
@RequestMapping(value="banip")//封禁ip public void banip(HttpServletResponse resp,HttpSession session,String ip,String mark,String time) throws IOException{ User loginUser = (User) session.getAttribute("loginUser"); if (loginUser == null) { return ; }else if(!"admin".equals(loginUser.getMission())){ //添加管理员的再次验证 return ; } Date date = new Date(); Ipset ip1 = ipsetBiz.selectip(ip); boolean isnull = false; if(ip1==null) { ip1=new Ipset(); ip1.setIp(ip); isnull =true; } ip1.setIp(ip); ip1.setMark(mark); ip1.setType("1"); switch (time) { case "5m": if (date.getMinutes() > 55) { date.setMinutes(date.getMinutes() - 55); date.setHours(date.getHours() + 1); } else { date.setMinutes(date.getMinutes() + 5); } ip1.setBantime(date); break; case "2h": date.setHours(date.getHours() + 2); ip1.setBantime(date); break; case "1d": date.setDate(date.getDate() + 1); ip1.setBantime(date); break; case "1m": date.setMonth(date.getMonth() + 1); ip1.setBantime(date); break; case "1y": date.setYear(date.getYear() + 1); ip1.setBantime(date); break; case "ever": date.setYear(date.getYear() + 99); ip1.setBantime(date); break; } if(isnull) { ipsetBiz.insert(ip1); }else { ipsetBiz.updateByPrimaryKeySelective(ip1); } resp.setCharacterEncoding("utf-8"); resp.getWriter().write("封禁成功!封禁至:"+date); }
Example 20
Source File: ReportGeneratorTest.java From freeacs with MIT License | 4 votes |
@Test public void populateReportHWTable() throws SQLException { // Given: final Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2018); calendar.set(Calendar.MONTH, 10); calendar.set(Calendar.DAY_OF_MONTH, 15); final ReportGenerator reportGenerator = new ReportGenerator("Test", ScheduleType.DAILY, null, null); final DataSource fakeDataSource = mock(DataSource.class); final Connection fakeConnection = mock(Connection.class); final PreparedStatement fakePreparedStatement = mock(PreparedStatement.class); when(fakeConnection.prepareStatement(anyString())).thenReturn(fakePreparedStatement); when(fakeDataSource.getConnection()).thenReturn(fakeConnection); final Report<RecordHardware> hardwareReport = new Report<>(RecordHardware.class, PeriodType.ETERNITY); final Date tms = new Date(); tms.setYear(2018 - 1900); tms.setMonth(11 - 1); tms.setDate(1); final Key key = RecordHardware.keyFactory.makeKey( tms, PeriodType.DAY, "testunittype", "testprofile", "v1.0"); final RecordHardware recordHardware = new RecordHardware(tms, PeriodType.DAY, "testunittype", "testprofile", "v1.0"); hardwareReport.getMap().put(key, recordHardware); // When: reportGenerator.populateReportHWTable(fakeDataSource, hardwareReport, calendar); // Then: verify(fakeConnection) .prepareStatement( "insert into report_hw VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); verify(fakePreparedStatement).executeUpdate(); final long expectedTime = new TmsConverter(calendar).convert(tms, PeriodType.DAY).getTime(); final Timestamp expectedTimestamp = new Timestamp(expectedTime); verify(fakePreparedStatement).setTimestamp(1, expectedTimestamp); verify(fakePreparedStatement).setInt(2, PeriodType.DAY.getTypeInt()); verify(fakePreparedStatement).setString(3, "testunittype"); verify(fakePreparedStatement).setString(4, "testprofile"); verify(fakePreparedStatement).setString(5, "v1.0"); verify(fakePreparedStatement).setInt(6, 0); verify(fakePreparedStatement).setInt(7, 0); verify(fakePreparedStatement).setInt(8, 0); verify(fakePreparedStatement).setInt(9, 0); verify(fakePreparedStatement).setInt(10, 0); verify(fakePreparedStatement).setInt(11, 0); verify(fakePreparedStatement).setInt(12, 0); verify(fakePreparedStatement).setInt(13, 0); verify(fakePreparedStatement).setInt(14, 0); verify(fakePreparedStatement).setInt(15, 0); verify(fakePreparedStatement).setString(16, null); verify(fakePreparedStatement).setString(17, null); verify(fakePreparedStatement).setString(18, null); verify(fakePreparedStatement).setString(19, null); verify(fakePreparedStatement).setString(20, null); verify(fakePreparedStatement).setString(21, null); verify(fakePreparedStatement).setString(22, null); verify(fakePreparedStatement).setString(23, null); verify(fakePreparedStatement).setString(24, null); verify(fakePreparedStatement).setString(25, null); verify(fakePreparedStatement).setString(26, null); verify(fakePreparedStatement).setString(27, null); verify(fakePreparedStatement).setString(28, null); verify(fakeConnection).close(); }