Java Code Examples for java.util.Calendar#getTime()
The following examples show how to use
java.util.Calendar#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: CocosBcxApi.java From AndroidWallet with GNU General Public License v3.0 | 6 votes |
/** * sign transaction with active private_key * * @param tx * @return * @throws NetworkStatusException */ private String sign_transaction(signed_operate tx, account_object account_object) throws NetworkStatusException, AuthorityException { dynamic_global_property_object dynamicGlobalPropertyObject = get_dynamic_global_properties(); tx.set_reference_block(dynamicGlobalPropertyObject.head_block_id); Date dateObject = dynamicGlobalPropertyObject.time; Calendar calender = Calendar.getInstance(); calender.setTime(dateObject); calender.add(Calendar.SECOND, 30); dateObject = calender.getTime(); tx.set_expiration(dateObject); HashMap<types.public_key_type, Integer> key_auths = account_object.active.key_auths; for (Map.Entry<types.public_key_type, Integer> entry : key_auths.entrySet()) { types.private_key_type privateKey = mHashMapPub2Private.get(entry.getKey()); if (privateKey != null) { tx.sign(privateKey, mWebSocketApi.get_chain_id()); } else { throw new AuthorityException("Author failed! make sure you logined and have active permission"); } } LogUtils.i("sign_transaction", global_config_object.getInstance().getGsonBuilder().create().toJson(tx)); return mWebSocketApi.broadcast_transaction(tx); }
Example 2
Source File: TimeUtils.java From AssistantBySDK with Apache License 2.0 | 6 votes |
/** * 一个月前的今天0点0时0分0秒0毫秒 * * @return */ public static Date lastMonthBefore() { Calendar cl = Calendar.getInstance(); cl.set(Calendar.HOUR_OF_DAY, 0); cl.set(Calendar.MINUTE, 0); cl.set(Calendar.SECOND, 0); cl.set(Calendar.MILLISECOND, 0); int month = cl.get(Calendar.MONTH); int tm = Math.abs(month + 11) % 12; if (tm > month) { cl.set(Calendar.YEAR, cl.get(Calendar.YEAR) - 1); } cl.set(Calendar.MONTH, tm); return cl.getTime(); }
Example 3
Source File: DateDataFieldTest.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test for @link org.jetel.data.DateDataField.equals(Object obj) * */ public void test_equals() { Calendar calendar = new GregorianCalendar(2003,4,10); Date trialTime1 = null; trialTime1 = calendar.getTime(); aDateDataField1.setValue(trialTime1); aDateDataField4.setValue(trialTime1); assertTrue(aDateDataField1.equals(aDateDataField4)); Calendar calendar2 = new GregorianCalendar(2003,6,10); Date trialTime2 = null; trialTime2 = calendar2.getTime(); aDateDataField4.setValue(trialTime2); assertFalse(aDateDataField1.equals(aDateDataField4)); assertTrue(aDateDataField3.isNull()); aDateDataField3.setToDefaultValue(); assertFalse(aDateDataField3.isNull()); assertEquals(new GregorianCalendar(2100,02,31).getTime(), aDateDataField3.getValue()); }
Example 4
Source File: RowCellWalkerImplTest.java From fastods with GNU General Public License v3.0 | 6 votes |
@Test public final void testDate() { final Calendar c = Calendar.getInstance(); c.setTimeInMillis(TIME_IN_MILLIS); final Date date = c.getTime(); PowerMock.resetAll(); expect(this.row.getOrCreateCell(10)).andReturn(this.cell); this.cell.setDateValue(date); PowerMock.replayAll(); this.cellWalker.to(10); this.cellWalker.setDateValue(date); PowerMock.verifyAll(); }
Example 5
Source File: AbstractSpringIntegrationTest.java From apollo with Apache License 2.0 | 5 votes |
protected Date assembleDate(int year, int month, int day, int hour, int minute, int second, int millisecond) { Calendar date = Calendar.getInstance(); date.set(year, month - 1, day, hour, minute, second); //Month in Calendar is 0 based date.set(Calendar.MILLISECOND, millisecond); return date.getTime(); }
Example 6
Source File: InternationalBAT.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static boolean testRequiredLocales() { boolean pass = true; TimeZone.setDefault(TimeZone.getTimeZone("GMT")); Calendar calendar = Calendar.getInstance(Locale.US); calendar.clear(); calendar.set(2001, 4, 10, 12, 0, 0); Date date = calendar.getTime(); Locale[] available = Locale.getAvailableLocales(); for (int i = 0; i < requiredLocales.length; i++) { Locale locale = requiredLocales[i]; boolean found = false; for (int j = 0; j < available.length; j++) { if (available[j].equals(locale)) { found = true; break; } } if (!found) { System.out.println("Locale not available: " + locale); pass = false; } else { DateFormat format = DateFormat.getDateInstance(DateFormat.FULL, locale); String dateString = format.format(date); if (!dateString.equals(requiredLocaleDates[i])) { System.out.println("Incorrect date string for locale " + locale + ". Expected: " + requiredLocaleDates[i] + ", got: " + dateString); pass = false; } } } return pass; }
Example 7
Source File: DateUtil.java From ZTuoExchange_framework with MIT License | 5 votes |
/** * 获取未来 第 past 天的日期 * * @param past * @return */ public static String getFetureDate(int past) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + past); Date today = calendar.getTime(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String result = format.format(today); return result; }
Example 8
Source File: VulnerabilityController.java From pacbot with Apache License 2.0 | 5 votes |
@RequestMapping(path = "/v1/trend/compliance/vulnerabilities", method = RequestMethod.POST) public ResponseEntity<Object> getVulnTrend(@RequestBody(required = true) CompliantTrendRequest request) { Map<String, Object> response = new HashMap<>(); String assetGroup = request.getAg(); Date input = request.getFrom(); if (input == null) { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("UTC")); cal.add(Calendar.DATE, NEG_THIRTY); input = cal.getTime(); } Instant instant = input.toInstant(); ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault()); LocalDate fromDate = zdt.toLocalDate(); LocalDate toDate = LocalDate.now(); if (Strings.isNullOrEmpty(assetGroup)) { return ResponseUtils.buildFailureResponse(new Exception(ASSET_MANDATORY)); } try { Map<String, Object> ruleTrendProgressList = vulnerabilityService.getTrendProgress(assetGroup, null, fromDate, toDate, "vulncompliance"); response.put(RESPONSE, ruleTrendProgressList); } catch (ServiceException e) { LOGGER.error("Exception in getVulnTrend", e.getMessage()); return ResponseUtils.buildFailureResponse(e); } return ResponseUtils.buildSucessResponse(response); }
Example 9
Source File: PitClassMeetingUtilPeriod.java From unitime with Apache License 2.0 | 5 votes |
public Date periodDateTime() { Calendar c = Calendar.getInstance(Locale.US); c.setTime(this.getPitClassMeeting().getMeetingDate()); int min = (this.getTimeSlot().intValue()*Constants.SLOT_LENGTH_MIN + Constants.FIRST_SLOT_TIME_MIN); c.set(Calendar.HOUR, min/60); c.set(Calendar.MINUTE, min%60); return c.getTime(); }
Example 10
Source File: DateTool.java From xxl-tool with GNU General Public License v3.0 | 5 votes |
private static Date add(final Date date, final int calendarField, final int amount) { if (date == null) { return null; } final Calendar c = Calendar.getInstance(); c.setTime(date); c.add(calendarField, amount); return c.getTime(); }
Example 11
Source File: TimeUtils.java From AssistantBySDK with Apache License 2.0 | 5 votes |
/** * 取今天的日期 * * @return */ //获取今天的日期,没有时分秒 public static Date getTodayDate() { Calendar cl = Calendar.getInstance(); cl.setTimeInMillis(System.currentTimeMillis()); cl.set(Calendar.HOUR_OF_DAY, 0); cl.set(Calendar.MINUTE, 0); cl.set(Calendar.SECOND, 0); cl.set(Calendar.MILLISECOND, 0); return cl.getTime(); }
Example 12
Source File: Meeting.java From unitime with Apache License 2.0 | 5 votes |
public Date getStartTime() { Calendar c = Calendar.getInstance(Locale.US); c.setTime(getMeetingDate()); int min = (getStartPeriod().intValue()*Constants.SLOT_LENGTH_MIN + Constants.FIRST_SLOT_TIME_MIN)+(getStartOffset()==null?0:getStartOffset()); c.set(Calendar.HOUR, min/60); c.set(Calendar.MINUTE, min%60); return c.getTime(); }
Example 13
Source File: DateUtils.java From litchi with Apache License 2.0 | 5 votes |
/** * 获取下周一0时 * @param millis * @return */ public static Date getNextWeekMonday0AM(long millis) { Calendar calendar = getCalendar(); calendar.setTimeInMillis(millis); calendar.add(Calendar.WEEK_OF_YEAR, 1); calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); return calendar.getTime(); }
Example 14
Source File: GeneratorErrorService.java From SkaETL with Apache License 2.0 | 4 votes |
public Date addMonthToTime(int monthToAdd, Date date) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(date.getTime()); cal.add(Calendar.MONTH, monthToAdd); return cal.getTime(); }
Example 15
Source File: DateUtils.java From search-spring-boot-starter with Apache License 2.0 | 4 votes |
public static Date addHour(Date date, Integer hour) { Calendar calendar = new GregorianCalendar(); calendar.setTime(date); calendar.add(Calendar.HOUR_OF_DAY, hour); return calendar.getTime(); }
Example 16
Source File: DateUtilsTest.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Tests the Changes Made by LANG-346 to the DateUtils.modify() private method invoked * by DateUtils.round(). */ @Test public void testRoundLang346() throws Exception { TimeZone.setDefault(defaultZone); dateTimeParser.setTimeZone(defaultZone); Calendar testCalendar = Calendar.getInstance(); testCalendar.set(2007, 6, 2, 8, 8, 50); Date date = testCalendar.getTime(); assertEquals("Minute Round Up Failed", dateTimeParser.parse("July 2, 2007 08:09:00.000"), DateUtils.round(date, Calendar.MINUTE)); testCalendar.set(2007, 6, 2, 8, 8, 20); date = testCalendar.getTime(); assertEquals("Minute No Round Failed", dateTimeParser.parse("July 2, 2007 08:08:00.000"), DateUtils.round(date, Calendar.MINUTE)); testCalendar.set(2007, 6, 2, 8, 8, 50); testCalendar.set(Calendar.MILLISECOND, 600); date = testCalendar.getTime(); assertEquals("Second Round Up with 600 Milli Seconds Failed", dateTimeParser.parse("July 2, 2007 08:08:51.000"), DateUtils.round(date, Calendar.SECOND)); testCalendar.set(2007, 6, 2, 8, 8, 50); testCalendar.set(Calendar.MILLISECOND, 200); date = testCalendar.getTime(); assertEquals("Second Round Down with 200 Milli Seconds Failed", dateTimeParser.parse("July 2, 2007 08:08:50.000"), DateUtils.round(date, Calendar.SECOND)); testCalendar.set(2007, 6, 2, 8, 8, 20); testCalendar.set(Calendar.MILLISECOND, 600); date = testCalendar.getTime(); assertEquals("Second Round Up with 200 Milli Seconds Failed", dateTimeParser.parse("July 2, 2007 08:08:21.000"), DateUtils.round(date, Calendar.SECOND)); testCalendar.set(2007, 6, 2, 8, 8, 20); testCalendar.set(Calendar.MILLISECOND, 200); date = testCalendar.getTime(); assertEquals("Second Round Down with 200 Milli Seconds Failed", dateTimeParser.parse("July 2, 2007 08:08:20.000"), DateUtils.round(date, Calendar.SECOND)); testCalendar.set(2007, 6, 2, 8, 8, 50); date = testCalendar.getTime(); assertEquals("Hour Round Down Failed", dateTimeParser.parse("July 2, 2007 08:00:00.000"), DateUtils.round(date, Calendar.HOUR)); testCalendar.set(2007, 6, 2, 8, 31, 50); date = testCalendar.getTime(); assertEquals("Hour Round Up Failed", dateTimeParser.parse("July 2, 2007 09:00:00.000"), DateUtils.round(date, Calendar.HOUR)); }
Example 17
Source File: LimitedTimeSecurityKey.java From huaweicloud-sdk-java-obs with Apache License 2.0 | 4 votes |
private static Date getUtcTime() { Calendar calendar = Calendar.getInstance(); int offset = calendar.get(Calendar.ZONE_OFFSET); calendar.add(Calendar.MILLISECOND, -offset); return calendar.getTime(); }
Example 18
Source File: IdTokenVerifier.java From auth0-java-mvc-common with MIT License | 4 votes |
/** * Verifies a provided ID Token follows the OIDC specification. * See https://openid.net/specs/openid-connect-core-1_0-final.html#IDTokenValidation * * @param token the ID Token to verify. * @param verifyOptions the verification options, like audience, issuer, algorithm. * @throws TokenValidationException If the ID Token is null, its signing algorithm not supported, its signature invalid or one of its claim invalid. */ void verify(String token, Options verifyOptions) throws TokenValidationException { Validate.notNull(verifyOptions); if (isEmpty(token)) { throw new TokenValidationException("ID token is required but missing"); } DecodedJWT decoded = verifyOptions.verifier.verifySignature(token); if (isEmpty(decoded.getIssuer())) { throw new TokenValidationException("Issuer (iss) claim must be a string present in the ID token"); } if (!decoded.getIssuer().equals(verifyOptions.issuer)) { throw new TokenValidationException(String.format("Issuer (iss) claim mismatch in the ID token, expected \"%s\", found \"%s\"", verifyOptions.issuer, decoded.getIssuer())); } if (isEmpty(decoded.getSubject())) { throw new TokenValidationException("Subject (sub) claim must be a string present in the ID token"); } final List<String> audience = decoded.getAudience(); if (audience == null) { throw new TokenValidationException("Audience (aud) claim must be a string or array of strings present in the ID token"); } if (!audience.contains(verifyOptions.audience)) { throw new TokenValidationException(String.format("Audience (aud) claim mismatch in the ID token; expected \"%s\" but found \"%s\"", verifyOptions.audience, decoded.getAudience())); } final Calendar cal = Calendar.getInstance(); final Date now = verifyOptions.clock != null ? verifyOptions.clock : cal.getTime(); final int clockSkew = verifyOptions.clockSkew != null ? verifyOptions.clockSkew : DEFAULT_CLOCK_SKEW; if (decoded.getExpiresAt() == null) { throw new TokenValidationException("Expiration Time (exp) claim must be a number present in the ID token"); } cal.setTime(decoded.getExpiresAt()); cal.add(Calendar.SECOND, clockSkew); Date expDate = cal.getTime(); if (now.after(expDate)) { throw new TokenValidationException(String.format("Expiration Time (exp) claim error in the ID token; current time (%d) is after expiration time (%d)", now.getTime() / 1000, expDate.getTime() / 1000)); } if (decoded.getIssuedAt() == null) { throw new TokenValidationException("Issued At (iat) claim must be a number present in the ID token"); } cal.setTime(decoded.getIssuedAt()); cal.add(Calendar.SECOND, -1 * clockSkew); if (verifyOptions.nonce != null) { String nonceClaim = decoded.getClaim(NONCE_CLAIM).asString(); if (isEmpty(nonceClaim)) { throw new TokenValidationException("Nonce (nonce) claim must be a string present in the ID token"); } if (!verifyOptions.nonce.equals(nonceClaim)) { throw new TokenValidationException(String.format("Nonce (nonce) claim mismatch in the ID token; expected \"%s\", found \"%s\"", verifyOptions.nonce, nonceClaim)); } } if (audience.size() > 1) { String azpClaim = decoded.getClaim(AZP_CLAIM).asString(); if (isEmpty(azpClaim)) { throw new TokenValidationException("Authorized Party (azp) claim must be a string present in the ID token when Audience (aud) claim has multiple values"); } if (!verifyOptions.audience.equals(azpClaim)) { throw new TokenValidationException(String.format("Authorized Party (azp) claim mismatch in the ID token; expected \"%s\", found \"%s\"", verifyOptions.audience, azpClaim)); } } if (verifyOptions.maxAge != null) { Date authTime = decoded.getClaim(AUTH_TIME_CLAIM).asDate(); if (authTime == null) { throw new TokenValidationException("Authentication Time (auth_time) claim must be a number present in the ID token when Max Age (max_age) is specified"); } cal.setTime(authTime); cal.add(Calendar.SECOND, verifyOptions.maxAge); cal.add(Calendar.SECOND, clockSkew); Date authTimeDate = cal.getTime(); if (now.after(authTimeDate)) { throw new TokenValidationException(String.format("Authentication Time (auth_time) claim in the ID token indicates that too much time has passed since the last end-user authentication. Current time (%d) is after last auth at (%d)", now.getTime() / 1000, authTimeDate.getTime() / 1000)); } } }
Example 19
Source File: BandwidthRestrictionsController.java From webcurator with Apache License 2.0 | 4 votes |
/** * Create a map of bandwidth restirctions to display on the UI. * * @param aDay * the list of the days persisted bandwidth restrictions * @return the list of the days display bandwidth restrictions */ private List<BandwidthRestriction> createDaysDisplayRestrictions(List<BandwidthRestriction> aDay) { List<BandwidthRestriction> displayDay = new ArrayList<BandwidthRestriction>(); Calendar cal = Calendar.getInstance(); Date dfltStart = BandwidthRestriction.getDefaultStartTime(); Date dfltEnd = BandwidthRestriction.getDefaultEndTime(); BandwidthRestriction dbr = null; BandwidthRestriction br = null; Iterator<BandwidthRestriction> it = aDay.iterator(); while (it.hasNext()) { br = it.next(); if (br.getStartTime().after(dfltStart)) { dbr = new BandwidthRestriction(); dbr.setBandwidth(0); dbr.setDayOfWeek(br.getDayOfWeek()); dbr.setStartTime(dfltStart); dbr.setAllowOptimize(br.isAllowOptimize()); cal.setTime(br.getStartTime()); cal.add(Calendar.SECOND, -1); dbr.setEndTime(cal.getTime()); displayDay.add(dbr); } displayDay.add(br); cal.setTime(br.getEndTime()); cal.add(Calendar.SECOND, 1); dfltStart = cal.getTime(); } if (br.getEndTime().before(dfltEnd)) { dbr = new BandwidthRestriction(); dbr.setBandwidth(0); dbr.setDayOfWeek(br.getDayOfWeek()); cal.setTime(br.getEndTime()); cal.add(Calendar.SECOND, 1); dbr.setStartTime(cal.getTime()); dbr.setEndTime(dfltEnd); dbr.setAllowOptimize(br.isAllowOptimize()); displayDay.add(dbr); } return displayDay; }
Example 20
Source File: Lang_65_DateUtils_t.java From coming with MIT License | 3 votes |
/** * <p>Round this date, leaving the field specified as the most * significant field.</p> * * <p>For example, if you had the datetime of 28 Mar 2002 * 13:45:01.231, if this was passed with HOUR, it would return * 28 Mar 2002 14:00:00.000. If this was passed with MONTH, it * would return 1 April 2002 0:00:00.000.</p> * * <p>For a date in a timezone that handles the change to daylight * saving time, rounding to Calendar.HOUR_OF_DAY will behave as follows. * Suppose daylight saving time begins at 02:00 on March 30. Rounding a * date that crosses this time would produce the following values: * <ul> * <li>March 30, 2003 01:10 rounds to March 30, 2003 01:00</li> * <li>March 30, 2003 01:40 rounds to March 30, 2003 03:00</li> * <li>March 30, 2003 02:10 rounds to March 30, 2003 03:00</li> * <li>March 30, 2003 02:40 rounds to March 30, 2003 04:00</li> * </ul> * </p> * * @param date the date to work with * @param field the field from <code>Calendar</code> * or <code>SEMI_MONTH</code> * @return the rounded date * @throws IllegalArgumentException if the date is <code>null</code> * @throws ArithmeticException if the year is over 280 million */ public static Date round(Date date, int field) { if (date == null) { throw new IllegalArgumentException("The date must not be null"); } Calendar gval = Calendar.getInstance(); gval.setTime(date); modify(gval, field, true); return gval.getTime(); }