Java Code Examples for java.util.GregorianCalendar#getTime()
The following examples show how to use
java.util.GregorianCalendar#getTime() .
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: DefaultBusinessCalendar.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
protected Date addSingleUnitQuantity(Date startDate, String singleUnitQuantity) { int spaceIndex = singleUnitQuantity.indexOf(" "); if (spaceIndex==-1 || singleUnitQuantity.length() < spaceIndex+1) { throw new ProcessEngineException("invalid duedate format: "+singleUnitQuantity); } String quantityText = singleUnitQuantity.substring(0, spaceIndex); Integer quantity = new Integer(quantityText); String unitText = singleUnitQuantity .substring(spaceIndex+1) .trim() .toLowerCase(); int unit = units.get(unitText); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(startDate); calendar.add(unit, quantity); return calendar.getTime(); }
Example 2
Source File: HibernateSessionDAO.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void cleanOldSessions(int ttl) { if (ttl > 0) { Date today = new Date(); GregorianCalendar cal = new GregorianCalendar(); cal.add(Calendar.DAY_OF_MONTH, -ttl); Date ldDate = cal.getTime(); try { int rowsUpdated = jdbcUpdate("UPDATE ld_session SET ld_deleted = 1, ld_lastmodified = ?" + " WHERE ld_deleted = 0 AND ld_creation < ?", today, ldDate); log.info("cleanOldSessions rows updated: {}", rowsUpdated); } catch (Exception e) { if (log.isErrorEnabled()) log.error(e.getMessage(), e); } } }
Example 3
Source File: RecurrencePeriod.java From financisto with GNU General Public License v2.0 | 6 votes |
static Date dateValueToDate(DateValue dvUtc) { GregorianCalendar c = new GregorianCalendar(); DateValue dv = TimeUtils.fromUtc(dvUtc, c.getTimeZone()); if (dv instanceof TimeValue) { TimeValue tv = (TimeValue) dv; c.set(dv.year(), dv.month() - 1, // java.util's dates are zero-indexed dv.day(), tv.hour(), tv.minute(), tv.second()); } else { c.set(dv.year(), dv.month() - 1, // java.util's dates are zero-indexed dv.day(), 0, 0, 0); } c.set(Calendar.MILLISECOND, 0); return c.getTime(); }
Example 4
Source File: TestDateUtil.java From ranger with Apache License 2.0 | 6 votes |
@Test public void testGetLocalDateForUTCDate(){ Date dt = new Date(); Calendar local=Calendar.getInstance(); int offset = local.getTimeZone().getOffset(local.getTimeInMillis()); GregorianCalendar utc = new GregorianCalendar(gmtTimeZone); utc.setTimeInMillis(dt.getTime()); utc.add(Calendar.MILLISECOND, offset); Date expectedDate = utc.getTime(); Date actualDate = dateUtil.getLocalDateForUTCDate(dt); Assert.assertEquals(actualDate.getDate(),expectedDate.getDate()); Assert.assertEquals(actualDate.getMinutes(),expectedDate.getMinutes()); Assert.assertEquals(actualDate.getHours(),expectedDate.getHours()); }
Example 5
Source File: DateTypeTest.java From json-data-generator with Apache License 2.0 | 6 votes |
/** * Test of getNextRandomValue method, of class DateType. */ @Test public void testGetNextRandomValueWithMin() { System.out.println("getNextRandomValue"); String[] launchArguments = {minDate}; DateType instance = new DateType(); //test it 1000 times for (int i = 0; i < 1000; i++) { GregorianCalendar cal = new GregorianCalendar(); cal.set(GregorianCalendar.MILLISECOND, 0); Date now = cal.getTime(); instance.setLaunchArguments(launchArguments); Date result = instance.getNextRandomValue(); assertTrue("Testing that " + result + " is after " + min, result.after(min) || result.equals(min)); assertTrue("Testing that " + result + " is before " + now, result.before(now) || result.equals(now)); } }
Example 6
Source File: DateUtils.java From RipplePower with Apache License 2.0 | 5 votes |
/** * 日期累加 * * @param year * @param month * @param day * @param seed * @param pedometer * @return * @throws Exception */ public static String toDateProgression(int year, int month, int day, String seed, int pedometer) throws Exception { GregorianCalendar dateAntetype = new GregorianCalendar(year, month - 1, day); if ("year".equals(seed)) dateAntetype.add(GregorianCalendar.YEAR, pedometer); else if ("month".equals(seed)) dateAntetype.add(GregorianCalendar.MONTH, pedometer); else if ("day".equals(seed)) dateAntetype.add(GregorianCalendar.DATE, pedometer); Date d = dateAntetype.getTime(); DateFormat df = DateFormat.getDateInstance(); return df.format(d); }
Example 7
Source File: StubCheckoutPreferenceUtils.java From px-android with MIT License | 5 votes |
public static CheckoutPreference stubInactivePreferenceAndPayer() { GregorianCalendar calendar = new GregorianCalendar(2100, 3, 3); //Date should be after that today Date date = calendar.getTime(); return stubBuilderOneItemAndPayer() .setActiveFrom(date) .build(); }
Example 8
Source File: DownloadData.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
public Date calculateDeleteDate(Date currentDate, int offset) { Date returnDate = new Date(); if (currentDate != null) { // just to be sure... GregorianCalendar tmpCal = new GregorianCalendar(); tmpCal.setTime(currentDate); tmpCal.add(Calendar.DAY_OF_YEAR,offset); returnDate = tmpCal.getTime(); } return returnDate; }
Example 9
Source File: YesterdayFunction.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
private static Date yesterday( final FormulaContext context ) { final LocalizationContext localizationContext = context.getLocalizationContext(); final GregorianCalendar gc = new GregorianCalendar( localizationContext.getTimeZone(), localizationContext.getLocale() ); gc.setTime( context.getCurrentDate() ); gc.set( Calendar.MILLISECOND, 0 ); gc.add( Calendar.DAY_OF_MONTH, -1 ); return gc.getTime(); }
Example 10
Source File: DateMath.java From FHIR with Apache License 2.0 | 5 votes |
/** * Add howMany months to the given {@link Date} * @param d * @param howMany * @return */ public static Date addMonths(Date d, int howMany) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(d); gc.add(Calendar.MONTH, howMany); return gc.getTime(); }
Example 11
Source File: WebServiceTaskTest.java From flowable-engine with Apache License 2.0 | 5 votes |
/** * Check the JSON conversion of a SOAP response XML part into JSon variable */ @Test @Deployment public void testJsonDataObject() throws Exception { final String myString = "my-string"; final GregorianCalendar myCalendar = new GregorianCalendar(2020, 1, 20, 0, 0, 0); final Date myDate = myCalendar.getTime(); this.webServiceMock.setDataStructure(myString, myDate); processEngineConfiguration.addWsEndpointAddress( new QName("http://webservice.impl.engine.flowable.org/", "CounterImplPort"), new URL(WEBSERVICE_MOCK_ADDRESS)); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("jsonDataObject"); waitForJobExecutorToProcessAllJobs(10000L, 250L); assertThat(processInstance.isEnded()).isTrue(); final HistoricProcessInstance histProcInst = historyService.createHistoricProcessInstanceQuery() .processInstanceId(processInstance.getId()).includeProcessVariables().singleResult(); final Object currentStructure = histProcInst.getProcessVariables().get("currentStructure"); assertThat(currentStructure).isInstanceOf(JsonNode.class); final JsonNode currentStructureJson = (JsonNode) currentStructure; assertThat(currentStructureJson.findValue("eltString").asText()).isEqualTo(myString); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); final String myDateJson = currentStructureJson.findValue("eltDate").asText(); assertThat(sdf.parse(myDateJson)).isEqualTo(myDate); }
Example 12
Source File: Util.java From Outlook-SDK-Android with MIT License | 5 votes |
public static Date getUTCDate(int year, int month, int day, int hour, int minute, int second) { GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("utc")); int dateMonth = month - 1; calendar.set(year, dateMonth, day, hour, minute, second); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTime(); }
Example 13
Source File: DateFormatUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenGregorianCalendar_whenCustomizedDateFormatSymbols_thenChangedDayNames() { GregorianCalendar gregorianCalendar = new GregorianCalendar(2018, 1, 1, 10, 15, 20); Date date = gregorianCalendar.getTime(); Locale.setDefault(new Locale("pl", "PL")); DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(); dateFormatSymbols.setWeekdays(new String[]{"A", "B", "C", "D", "E", "F", "G", "H"}); SimpleDateFormat standardDateFormat = new SimpleDateFormat("EEEE-MMMM-yyyy HH:mm:ss:SSS"); SimpleDateFormat newDaysDateFormat = new SimpleDateFormat("EEEE-MMMM-yyyy HH:mm:ss:SSS", dateFormatSymbols); Assert.assertEquals("czwartek-lutego-2018 10:15:20:000", standardDateFormat.format(date)); Assert.assertEquals("F-lutego-2018 10:15:20:000", newDaysDateFormat.format(date)); }
Example 14
Source File: CalendarableItem.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * @param source * @param into */ private Date setDateComponentOf(Date source, Date into) { GregorianCalendar mergeSource = new GregorianCalendar(); mergeSource.setTime(source); GregorianCalendar mergeTarget = new GregorianCalendar(); mergeTarget.setTime(into); mergeTarget.set(Calendar.MONTH, mergeSource.get(Calendar.MONTH)); mergeTarget.set(Calendar.DAY_OF_MONTH, mergeSource.get(Calendar.DAY_OF_MONTH)); mergeTarget.set(Calendar.YEAR, mergeSource.get(Calendar.YEAR)); return mergeTarget.getTime(); }
Example 15
Source File: DateUtil.java From ranger with Apache License 2.0 | 5 votes |
public static Date getUTCDate(long epoh) { if(epoh==0){ return null; } try{ Calendar local=Calendar.getInstance(); int offset = local.getTimeZone().getOffset(epoh); GregorianCalendar utc = new GregorianCalendar(gmtTimeZone); utc.setTimeInMillis(epoh); utc.add(Calendar.MILLISECOND, -offset); return utc.getTime(); }catch(Exception ex){ return null; } }
Example 16
Source File: AbstractWebModulePlugin.java From BIMserver with GNU Affero General Public License v3.0 | 4 votes |
private static Date makeExpiresDate() { GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.add(Calendar.DAY_OF_YEAR, 120); return gregorianCalendar.getTime(); }
Example 17
Source File: AddStickyJobTocTalendJobMigrationTask.java From tesb-studio-se with Apache License 2.0 | 4 votes |
public Date getOrder() { GregorianCalendar gc = new GregorianCalendar(2017, 2, 24, 19, 00, 00); return gc.getTime(); }
Example 18
Source File: DateConvertUtil.java From spring-boot-demo-all with Apache License 2.0 | 4 votes |
public static Date getDateByAddMinutes(Date inDate, int minutes) { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(inDate); calendar.add(Calendar.MINUTE, minutes); return calendar.getTime(); }
Example 19
Source File: AddBeansDefaultLibrariesMigrationTask.java From tesb-studio-se with Apache License 2.0 | 4 votes |
@Override public Date getOrder() { GregorianCalendar gc = new GregorianCalendar(2017, 3, 25, 0, 0, 0); return gc.getTime(); }
Example 20
Source File: ZYDateUtils.java From Viewer with Apache License 2.0 | 3 votes |
/** * 对日期(时间)中由field参数指定的日期成员进行加减计算. <br> * 例子: <br> * 如果Date类型的d为 2005年8月20日,那么 <br> * calculate(d,GregorianCalendar.YEAR,-10)的值为1995年8月20日 <br> * 而calculate(d,GregorianCalendar.YEAR,+10)的值为2015年8月20日 <br> * * @param d * 日期(时间). * @param field * 日期成员. <br> * 日期成员主要有: <br> * 年:GregorianCalendar.YEAR <br> * 月:GregorianCalendar.MONTH <br> * 日:GregorianCalendar.DATE <br> * 时:GregorianCalendar.HOUR <br> * 分:GregorianCalendar.MINUTE <br> * 秒:GregorianCalendar.SECOND <br> * 毫秒:GregorianCalendar.MILLISECOND <br> * @param amount * 加减计算的幅度.+n=加n个由参数field指定的日期成员值;-n=减n个由参数field代表的日期成员值. * @return 计算后的日期(时间). */ private static Date calculate(Date d, int field, int amount) { if (d == null) return null; GregorianCalendar g = new GregorianCalendar(); g.setGregorianChange(d); g.add(field, amount); return g.getTime(); }