List of usage examples for java.util Date setTime
public void setTime(long time)
From source file:Main.java
/** * getDateEnd/*w ww . j av a 2 s . c om*/ * @param date the date that needs to be converted to an end date * @return a date at 11:59 PM */ public static Date getDateEnd(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); cal.set(Calendar.MILLISECOND, 59); long time = cal.getTimeInMillis(); date.setTime(time); return date; }
From source file:com.swiftcorp.portal.common.util.CalendarUtils.java
public static Calendar stringToCalendarMillis(String millis) { Calendar cal = Calendar.getInstance(); if (millis == null || millis.equals("")) { return cal; }//ww w . j a v a 2 s .com try { Date date1 = new Date(); date1.setTime(Long.parseLong(millis)); cal.setTime(date1); } catch (Exception e) { log.info("getDateAsCalendar() : ", e); } return cal; }
From source file:net.firejack.platform.core.utils.DateUtils.java
/** * Decrements the date by one hour//from www.j a v a 2s . c o m * @param date - date to be decremented */ public static void decDateByHour(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(Calendar.HOUR, -1); date.setTime(cal.getTimeInMillis()); }
From source file:com.nextdoor.bender.Bender.java
protected static void invokeKinesisHandler(String stream_name, String source_file) throws HandlerException { String sourceArn = "arn:aws:kinesis:" + AWS_REGION + ":" + AWS_ACCOUNT + ":stream/" + stream_name; logger.info("Invoking the Kinesis Handler..."); TestContext ctx = getContext();/*from ww w. j a v a 2s . co m*/ KinesisHandler handler = new KinesisHandler(); /* * Set the arrival timestamp as the function run time. */ Date approximateArrivalTimestamp = new Date(); approximateArrivalTimestamp.setTime(System.currentTimeMillis()); /* * Open up the source file for events */ Scanner scan = null; try { scan = new Scanner(new File(source_file)); } catch (FileNotFoundException e) { logger.error("Could not find source file (" + source_file + "): " + e); System.exit(1); } /* * Create a series of KinesisEvents from the source file. All of these events will be treated as * a single batch that was pushed to Kinesis, so they will all have the same Arrival Time. */ logger.info("Parsing " + source_file + "..."); List<KinesisEvent.KinesisEventRecord> events = new ArrayList<KinesisEvent.KinesisEventRecord>(); int r = 0; /* * Walk through the source file. For each line in the file, turn the line into a KinesisRecord. */ while (scan.hasNextLine()) { String line = scan.nextLine(); Record rec = new Record(); rec.withPartitionKey("1").withSequenceNumber(r + "").withData(ByteBuffer.wrap(line.getBytes())) .withApproximateArrivalTimestamp(approximateArrivalTimestamp); KinesisEventRecord krecord = new KinesisEventRecord(); krecord.setKinesis(rec); krecord.setEventSourceARN(sourceArn); krecord.setEventID("shardId-000000000000:" + UUID.randomUUID()); events.add(krecord); r += 1; } logger.info("Read " + r + " records"); /* * Create the main Kinesis Event object - this holds all of the data and records that will be * passed into the Kinesis Handler. */ KinesisEvent kevent = new KinesisEvent(); kevent.setRecords(events); /* * Invoke handler */ handler.handler(kevent, ctx); handler.shutdown(); }
From source file:net.firejack.platform.core.utils.DateUtils.java
/** * Increments the date by one day//from w w w. j av a 2s. c om * @param date - date to be incremented */ public static void incDateByDay(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(Calendar.DAY_OF_MONTH, 1); date.setTime(cal.getTimeInMillis()); }
From source file:net.firejack.platform.core.utils.DateUtils.java
/** * Decrements the date by one week//from w ww .j av a 2 s. c o m * @param date - date to be decremented * @return decremented date */ public static Date decDateByWeek(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(Calendar.WEEK_OF_MONTH, -1); date.setTime(cal.getTimeInMillis()); return date; }
From source file:org.nuxeo.ecm.platform.web.common.requestcontroller.filter.NuxeoRequestControllerFilter.java
/** * Set cache parameters to httpResponse. *///from w ww . j a v a2 s . c o m public static void addCacheHeader(HttpServletResponse httpResponse, Boolean isPrivate, String cacheTime) { if (isPrivate) { httpResponse.setHeader("Cache-Control", "private, max-age=" + cacheTime); } else { httpResponse.setHeader("Cache-Control", "public, max-age=" + cacheTime); } // Generating expires using current date and adding cache time. // we are using the format Expires: Thu, 01 Dec 1994 16:00:00 GMT Date date = new Date(); long newDate = date.getTime() + new Long(cacheTime) * 1000; date.setTime(newDate); httpResponse.setHeader("Expires", HTTP_EXPIRES_DATE_FORMAT.format(date)); }
From source file:ConversionUtil.java
/** * convert into java.sql.Time (or into java.util.Calendar * /*w ww.j a va2 s . co m*/ * @param date * The date containing the time. * @param am * Whether this should be am (true) or pm (false) * @return */ public static Time convertDateToTime(Date date, boolean am) { if (date == null) { return null; } Calendar cal = new GregorianCalendar(); cal.setTime(date); int hourOfDay = cal.get(Calendar.HOUR_OF_DAY); if (am) { // Check to make sure that the hours are indeed am hours if (hourOfDay > 11) { cal.set(Calendar.HOUR_OF_DAY, hourOfDay - 12); date.setTime(cal.getTimeInMillis()); } } else { // Check to make sure that the hours are indeed pm hours if (cal.get(Calendar.HOUR_OF_DAY) < 11) { cal.set(Calendar.HOUR_OF_DAY, hourOfDay + 12); date.setTime(cal.getTimeInMillis()); } } return new Time(date.getTime()); }
From source file:me.calebjones.spacelaunchnow.utils.Utils.java
public static String getFormattedDateFromTimestamp(long timestampInMilliSeconds) { Date date = new Date(); date.setTime(timestampInMilliSeconds); return new SimpleDateFormat("h:mm a z - MMM d, yyyy ", Locale.US).format(date); }
From source file:MailDateFormatter.java
/** * Gets a <code>Date</code> object from a string representing a date in * 'Zulu' format (yyyyMMddTHHmmssZ)/* w ww .j a va 2 s .co m*/ * * @param utc * date in 'Zulu' format (yyyyMMddTHHmmssZ) * @return A <code>Date</code> object obtained starting from a time in * milliseconds from the Epoch */ public static Date parseUTCDate(String utc) { int day = 0; int month = 0; int year = 0; int hour = 0; int minute = 0; int second = 0; Calendar calendar = null; day = Integer.parseInt(utc.substring(6, 8)); month = Integer.parseInt(utc.substring(4, 6)); year = Integer.parseInt(utc.substring(0, 4)); hour = Integer.parseInt(utc.substring(9, 11)); minute = Integer.parseInt(utc.substring(11, 13)); second = Integer.parseInt(utc.substring(13, 15)); calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, second); Date date = calendar.getTime(); long dateInMillis = date.getTime(); date.setTime(dateInMillis + millisDeviceOffset); return date; }