List of usage examples for java.util Date setTime
public void setTime(long time)
From source file:com.fivesticks.time.activity.xwork.TimeResolver.java
public Date resolve() { if (this.date == null || this.timestring == null) throw new RuntimeException("Unable to resolve time."); Calendar c = new GregorianCalendar(); c.setTime(date);/*from www .j a va2 s . c om*/ int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); parseTimeString(); Calendar c2 = new GregorianCalendar(year, month, day, this.getResolvedHours(), this.getResolvedMinutes()); Date ret = new Date(); ret.setTime(c2.getTimeInMillis()); return ret; }
From source file:com.linuxbox.enkive.statistics.gathering.GatheringScheduler.java
private Date getEndTime() { Date endTime = new Date(); long intervalMS = interval * 60 * 1000; if (lastFireTime != null) { endTime.setTime(lastFireTime.getTime() + intervalMS); } else {//w ww .j av a2 s .c om long r = endTime.getTime() % intervalMS; endTime.setTime(endTime.getTime() - r); } return endTime; }
From source file:org.cloudifysource.esc.driver.provisioning.privateEc2.AmazonS3Uploader.java
/** * Returns a pre-signed URL for accessing an Amazon S3 resource. * //from ww w . j a v a2 s .co m * @param bucketName * The bucket where the resource lies. * @param objectKey * The key object. * @return A pre-signed URL for accessing an Amazon S3 resource. */ public String generatePresignedURL(final String bucketName, final String objectKey) { final Date expiration = new Date(); expiration.setTime(System.currentTimeMillis() + ONE_DAY_IN_MILLIS); final GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, objectKey); generatePresignedUrlRequest.setMethod(HttpMethod.GET); // Default. generatePresignedUrlRequest.setExpiration(expiration); URL generatePresignedObjectURL = s3client.generatePresignedUrl(generatePresignedUrlRequest); if (logger.isLoggable(Level.FINEST)) { logger.finest("Zip uploaded. Limited signed URL: " + generatePresignedObjectURL); } return generatePresignedObjectURL.toString(); }
From source file:org.power.commons.lang.util.time.DateUtils.java
/** * ????(?delay)//from w w w . j ava 2s.co m * * @param nowdate * @param delay * @param format * @return * @author kanghongwei */ public static String getNextDay2String(String nowdate, String delay, Format format) { try { SimpleDateFormat localFormat = (SimpleDateFormat) format; String mdate = ""; Date date = strToDateWithFormat(nowdate, localFormat); long myTime = (date.getTime() / 1000) + Integer.parseInt(delay) * 24 * 60 * 60; date.setTime(myTime * 1000); mdate = localFormat.format(date); return mdate; } catch (Exception e) { return ""; } }
From source file:nl.b3p.commons.taglib.WriteDateTag.java
/** * Process the start tag./* w w w . j a v a 2 s . c om*/ * * @exception JspException if a JSP exception has occurred */ public int doStartTag() throws JspException { // Look up the requested bean Object value = null; if (name != null) { // er zou een datum te vinden moeten zijn if (TagUtils.getInstance().lookup(pageContext, name, scope) == null) { return (SKIP_BODY); // Nothing to output // Look up the requested property value } value = TagUtils.getInstance().lookup(pageContext, name, property, scope); } if (value == null) { // een voorbeeld datum met locale wordt afgedrukt Date exValue = new Date(); value = exValue; } // Get locale of this request for date printing HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); Locale locale = request.getLocale(); // Print this property value to our output writer String output = null; if (value != null) { if (value instanceof Date) { output = FormUtils.DateToString((Date) value, locale); if (log.isDebugEnabled()) { log.debug("Date: " + output); } } else if (value instanceof Timestamp) { Timestamp temptime = (Timestamp) value; Date tempdate = new Date(); tempdate.setTime(temptime.getTime()); output = FormUtils.DateToString(tempdate, locale); if (log.isDebugEnabled()) { log.debug("Timestamp: " + output); } } else if (value instanceof String) { SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateInstance(); sdf.applyPattern("yyyy-MM-dd HH:mm"); Date tempdate = null; try { tempdate = sdf.parse((String) value); output = FormUtils.DateToString(tempdate, locale); if (log.isDebugEnabled()) { log.debug("String (yyyy-MM-dd HH:mm): " + output); } } catch (java.text.ParseException pe) { output = ((String) value).trim(); int spacedex = output.indexOf(' '); if (spacedex > 1) { output = output.substring(0, spacedex); } if (log.isDebugEnabled()) { log.debug("No conversion: " + output); } } } } TagUtils.getInstance().write(pageContext, output); // Continue processing this page return (SKIP_BODY); }
From source file:org.b3mn.poem.handler.CollectionHandler.java
protected Date parseDate(String strDate, boolean set1970OnError) { if (strDate != null) { try {//www. ja v a 2 s . com SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); return formatter.parse(strDate); } catch (ParseException e) { Calendar c = Calendar.getInstance(); c.set(1970, 1, 1); return c.getTime(); } } else { if (set1970OnError) { Calendar c = Calendar.getInstance(); c.set(1970, 1, 1); return c.getTime(); } else { Date date = new Date(); // TODO: Find the damn time bug. You have to add 24h to get all the models. Why ever... date.setTime(date.getTime() + 24 * 3600 * 1000); return date; } } }
From source file:com.jaspersoft.jasperserver.war.themes.ThemeResolverServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // Check if we can find a resource in the current theme //String resPath = req.getRequestURI().substring((req.getContextPath() + req.getServletPath()).length()); String resPath = req.getRequestURI().substring(req.getContextPath().length() + 1); ThemeResource themeResource = themeCache.getThemeResource(resPath); if (themeResource == null) { resp.sendError(404);/* w w w . j a v a 2s.c om*/ return; } // Set contentType String filename = resPath; if (filename.indexOf("/") >= 0) { filename = filename.substring(filename.lastIndexOf("/") + 1); } String contentType = servletContext.getMimeType(filename); if (contentType == null) { log.error("Cannot detect a response content type for the file : " + filename); resp.sendError(404); return; } resp.setContentType(contentType); // Get Last Modified date Date lastModified = themeResource.getLastModified(); // Get rid of ms lastModified.setTime(lastModified.getTime() / 1000 * 1000); // Set cache controlling HTTP Response Headers DateFormat df = getFormat(req.getLocale()); resp.setHeader("Cache-Control", "max-age=" + expiresInSecs + ", public"); resp.setHeader("Pragma", ""); resp.setHeader("Last-Modified", df.format(lastModified)); resp.setHeader("Expires", df.format(new Date(new Date().getTime() + expiresInSecs * 1000))); // Send 304 if resource has not been modified since last time requested String ifModSince = req.getHeader("If-Modified-Since"); try { Date modDate = df.parse(ifModSince); if (!lastModified.after(modDate)) { resp.setStatus(304); return; } } catch (Exception e) { } // Send the full content resp.setContentLength(themeResource.getContent().length); ServletOutputStream os = resp.getOutputStream(); os.write(themeResource.getContent()); os.flush(); os.close(); }
From source file:DateUtil.java
/** * Make the date go forward of the specified amount of minutes * The internal date is changed after this call. * * @return a reference to this DateUtil, for concatenation. *//* w ww . jav a 2 s .co m*/ public DateUtil addMinutes(int minutes) { Date d = cal.getTime(); long time = d.getTime(); time += minutes * 60 * 1000; d.setTime(time); cal.setTime(d); return this; }
From source file:org.jfree.data.time.SimpleTimePeriodTest.java
/** * Some simple checks for immutability./*w w w .j ava2 s . c om*/ */ @Test public void testImmutable() { SimpleTimePeriod p1 = new SimpleTimePeriod(new Date(10L), new Date(20L)); SimpleTimePeriod p2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(p1, p2); p1.getStart().setTime(11L); assertEquals(p1, p2); Date d1 = new Date(10L); Date d2 = new Date(20L); p1 = new SimpleTimePeriod(d1, d2); d1.setTime(11L); assertEquals(new Date(10L), p1.getStart()); }
From source file:DateUtil.java
/** * Make the date go back of the specified amount of days * The internal date is changed after this call. * * @return a reference to this DateUtil, for concatenation. *//*from w w w .ja va 2 s. co m*/ public DateUtil removeDays(int days) { Date d = cal.getTime(); long time = d.getTime(); time -= days * 24 * 3600 * 1000; d.setTime(time); cal.setTime(d); return this; }