List of usage examples for java.util Calendar SECOND
int SECOND
To view the source code for java.util Calendar SECOND.
Click Source Link
get
and set
indicating the second within the minute. From source file:com.oncecorp.visa3d.bridge.utility.JdbcUtils.java
/** * This method converts the java date into the long that point to the beginning * of the day.//from w w w.j av a 2 s.com * @param date The converted date object. * @param startEnd <tt>true</tt> day start time, <tt>false</tt> day end time. * @return The long that point to the beginning or end of the day. */ public static long dayValue(Date date, boolean startEnd) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.HOUR, startEnd ? 0 : 23); calendar.set(Calendar.MINUTE, startEnd ? 0 : 59); calendar.set(Calendar.SECOND, startEnd ? 0 : 59); calendar.set(Calendar.MILLISECOND, startEnd ? 0 : 999); return calendar.getTime().getTime(); }
From source file:fr.syncarnet.tasks.Task.java
/** * @param date/*from w w w . j av a 2 s .com*/ * The new date in UNIX time */ public void setDue(Calendar date) { this.modified = new Date().getTime(); if (date != null) { date.set(Calendar.HOUR_OF_DAY, 0); date.set(Calendar.MINUTE, 0); date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0); } this.due = date; }
From source file:com.adobe.acs.commons.http.headers.impl.MonthlyExpiresHeaderFilterTest.java
@Test public void testAdjustExpiresSameDayPast() throws Exception { Calendar actual = Calendar.getInstance(); actual.set(Calendar.SECOND, 0); actual.set(Calendar.MILLISECOND, 0); Calendar expected = Calendar.getInstance(); expected.setTime(actual.getTime());//www . ja v a 2 s. com expected.add(Calendar.MONTH, 1); final int month = expected.get(Calendar.MONTH); properties.put(MonthlyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_MONTH, expected.get(Calendar.DAY_OF_MONTH)); filter.doActivate(componentContext); filter.adjustExpires(actual); assertTrue(DateUtils.isSameInstant(expected, actual)); assertEquals(month, actual.get(Calendar.MONTH)); }
From source file:org.duracloud.mill.manifest.cleaner.ManifestCleanerDriver.java
/** * @param time//from ww w. j a v a 2 s .c om * @return * @throws ParseException */ private Date parseExpirationDate(String time) throws ParseException { Calendar c = Calendar.getInstance(); String pattern = "([0-9]+)([smhd])"; if (!time.matches(pattern)) { throw new ParseException(time + " is not a valid time value."); } int amount = Integer.parseInt(time.replaceAll(pattern, "$1")); String units = time.replaceAll(pattern, "$2"); int field = Calendar.SECOND; if (units.equals("m")) { field = Calendar.MINUTE; } else if (units.equals("h")) { field = Calendar.HOUR; } else if (units.equals("d")) { field = Calendar.DATE; } else { // should never happen. throw new RuntimeException("unit " + units + " not recognized."); } c.add(field, -1 * amount); return c.getTime(); }
From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.MarkerTimeChartDecorator.java
public void createChart() { XYPlot xyplot = (XYPlot) report.getPlot(); // if (this.decoratedChart instanceof TimeChartRenderer ) { if (this.results != null && !this.results.isEmpty()) { Iterator iter1 = this.results.iterator(); ValueMarker valuemarker = null;//from ww w.j a v a 2s.c o m BlockContainer blockcontainerLabel = new BlockContainer(new ColumnArrangement()); // blockcontainerLabel.setFrame( new LineBorder() ); int i = 0; while (iter1.hasNext()) { Object[] item = (Object[]) iter1.next(); Date date = (Date) item[1]; Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); valuemarker = new ValueMarker(cal.getTimeInMillis(), ChartColor.createDefaultPaintArray()[i], new BasicStroke(2.0F)); xyplot.addDomainMarker(valuemarker); LegendItem legendLabel = new LegendItem((String) item[0], null, null, null, new Line2D.Double(-7.0, 0.0, 7.0, 0.0), valuemarker.getPaint(), valuemarker.getStroke(), valuemarker.getPaint()); blockcontainerLabel.add(createLegendItemBlock(legendLabel, i)); i++; } createLegendBlock(blockcontainerLabel); } // } }
From source file:com.googlecode.jsfFlex.shared.util.JSONConverter.java
public static JSONArray convertJavaDateToASDateConstructorArguments(Calendar toConvert) { JSONArray dateConstructorArguments = new JSONArray(); dateConstructorArguments.put(toConvert.get(Calendar.YEAR)); dateConstructorArguments.put(toConvert.get(Calendar.MONTH)); dateConstructorArguments.put(toConvert.get(Calendar.DATE)); dateConstructorArguments.put(toConvert.get(Calendar.HOUR_OF_DAY)); dateConstructorArguments.put(toConvert.get(Calendar.MINUTE)); dateConstructorArguments.put(toConvert.get(Calendar.SECOND)); dateConstructorArguments.put(toConvert.get(Calendar.MILLISECOND)); return dateConstructorArguments; }
From source file:org.jfree.chart.demo.SegmentedHighLowChartDemo.java
/** * A demonstration application showing a high-low-open-close chart using a * segmented or non-segmented axis.//from w w w .j ava2s. c om * * @param title the frame title. * @param useSegmentedAxis use a segmented axis for this demo? * @param timelineType Type of timeline to use: 1=Monday through Friday, 2=Intraday */ public SegmentedHighLowChartDemo(final String title, final boolean useSegmentedAxis, final int timelineType) { super(title); System.out.println("\nMaking SegmentedHighLowChartDemo(" + title + ")"); // create a Calendar object with today's date at midnight final Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); // create a timeline for the demo SegmentedTimeline timeline = null; switch (timelineType) { case 1: timeline = SegmentedTimeline.newMondayThroughFridayTimeline(); break; case 2: timeline = SegmentedTimeline.newFifteenMinuteTimeline(); final Calendar cal2 = (Calendar) cal.clone(); cal2.add(Calendar.YEAR, 1); // add 1 year of baseTimeline's excluded segments (Saturdays and Sundays) as // exceptions of the intraday timeline timeline.addBaseTimelineExclusions(cal.getTime().getTime(), cal2.getTime().getTime()); break; default: System.out.println("Invalid timelineType."); System.exit(1); } // create a data set that has data for trading days (Monday through Friday). final DefaultHighLowDataset dataset = DemoDatasetFactory.createSegmentedHighLowDataset(timeline, cal.getTime()); final JFreeChart chart; if (useSegmentedAxis) { chart = ChartFactory.createHighLowChart(title, "Time", "Value", dataset, timeline, true); } else { chart = ChartFactory.createHighLowChart(title, "Time", "Value", dataset, true); } final DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis(); axis.setAutoRange(true); final TickUnits units = new TickUnits(); units.add(new DateTickUnit(DateTickUnit.DAY, 1, DateTickUnit.HOUR, 1, new SimpleDateFormat("d-MMM"))); units.add(new DateTickUnit(DateTickUnit.DAY, 2, DateTickUnit.HOUR, 1, new SimpleDateFormat("d-MMM"))); units.add(new DateTickUnit(DateTickUnit.DAY, 7, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM"))); units.add(new DateTickUnit(DateTickUnit.DAY, 15, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM"))); units.add(new DateTickUnit(DateTickUnit.DAY, 30, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM"))); axis.setStandardTickUnits(units); final NumberAxis vaxis = (NumberAxis) chart.getXYPlot().getRangeAxis(); vaxis.setAutoRangeIncludesZero(false); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:DateTime.java
/** Formats the value as an RFC 3339 date/time string. */ public String toStringRfc3339() { StringBuilder sb = new StringBuilder(); Calendar dateTime = new GregorianCalendar(GMT); long localTime = value; Integer tzShift = this.tzShift; if (tzShift != null) { localTime += tzShift.longValue() * 60000; }/*from w w w .j a v a 2 s . com*/ dateTime.setTimeInMillis(localTime); appendInt(sb, dateTime.get(Calendar.YEAR), 4); sb.append('-'); appendInt(sb, dateTime.get(Calendar.MONTH) + 1, 2); sb.append('-'); appendInt(sb, dateTime.get(Calendar.DAY_OF_MONTH), 2); if (!dateOnly) { sb.append('T'); appendInt(sb, dateTime.get(Calendar.HOUR_OF_DAY), 2); sb.append(':'); appendInt(sb, dateTime.get(Calendar.MINUTE), 2); sb.append(':'); appendInt(sb, dateTime.get(Calendar.SECOND), 2); if (dateTime.isSet(Calendar.MILLISECOND)) { sb.append('.'); appendInt(sb, dateTime.get(Calendar.MILLISECOND), 3); } } if (tzShift != null) { if (tzShift.intValue() == 0) { sb.append('Z'); } else { int absTzShift = tzShift.intValue(); if (tzShift > 0) { sb.append('+'); } else { sb.append('-'); absTzShift = -absTzShift; } int tzHours = absTzShift / 60; int tzMinutes = absTzShift % 60; appendInt(sb, tzHours, 2); sb.append(':'); appendInt(sb, tzMinutes, 2); } } return sb.toString(); }
From source file:com.autodomum.daylight.algorithm.DaylightAlgorithm.java
@Override public Date sunrise(final Coordinate coordinate, final Date date) { final Calendar calendar = GregorianCalendar.getInstance(); calendar.setTime(date);/* w w w . j a v a 2 s .c o m*/ final int day = calendar.get(Calendar.DAY_OF_YEAR); final double total = length(coordinate.getLatitude(), day); final int hours = (int) total; final int minutes = (int) ((((double) total) - ((double) hours)) * 60d); calendar.set(Calendar.HOUR_OF_DAY, 12); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.add(Calendar.HOUR_OF_DAY, -hours / 2); calendar.add(Calendar.MINUTE, -minutes / 2); calendar.add(Calendar.MINUTE, (int) localSolarTime(day)); final TimeZone timeZone = TimeZone.getDefault(); if (timeZone.inDaylightTime(date)) { calendar.add(Calendar.MILLISECOND, timeZone.getDSTSavings()); } return calendar.getTime(); }
From source file:com.silverpeas.jcrutil.RandomGenerator.java
public static Calendar getOutdatedCalendar() { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_MONTH, -(1 + random.nextInt(10))); calendar.set(Calendar.HOUR_OF_DAY, getRandomHour()); calendar.set(Calendar.MINUTE, getRandomMinutes()); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.setLenient(false);//w ww . jav a2 s .c o m try { calendar.getTime(); } catch (IllegalArgumentException ie) { return getOutdatedCalendar(); } return calendar; }