List of usage examples for java.util Calendar MILLISECOND
int MILLISECOND
To view the source code for java.util Calendar MILLISECOND.
Click Source Link
get
and set
indicating the millisecond within the second. 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 www.j a va 2s . c o m * @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:com.alibaba.otter.shared.common.utils.cache.RefreshMemoryMirror.java
/** * ?// w ww . j a v a 2 s . co m * * @param refreshObject * @return */ private boolean isExpired(RefreshObject refreshObject) { if (refreshObject == null) { return false; } Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(refreshObject.getTimestamp()); // calendar.add(Calendar.SECOND, period.intValue()); calendar.add(Calendar.MILLISECOND, period.intValue()); Date now = new Date(); return now.after(calendar.getTime()); }
From source file:fr.syncarnet.tasks.Task.java
/** * @param date/* w w w .j a v a 2 s . c o m*/ * 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 .j a v a2 s . c o m 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:ISO8601DateTimeFormat.java
/** * @see DateFormat#parse(String, ParsePosition) *///from ww w.jav a 2s . c o m public Date parse(String text, ParsePosition pos) { int i = pos.getIndex(); try { int year = Integer.valueOf(text.substring(i, i + 4)).intValue(); i += 4; if (text.charAt(i) != '-') { throw new NumberFormatException(); } i++; int month = Integer.valueOf(text.substring(i, i + 2)).intValue() - 1; i += 2; if (text.charAt(i) != '-') { throw new NumberFormatException(); } i++; int day = Integer.valueOf(text.substring(i, i + 2)).intValue(); i += 2; if (text.charAt(i) != 'T') { throw new NumberFormatException(); } i++; int hour = Integer.valueOf(text.substring(i, i + 2)).intValue(); i += 2; if (text.charAt(i) != ':') { throw new NumberFormatException(); } i++; int mins = Integer.valueOf(text.substring(i, i + 2)).intValue(); i += 2; int secs = 0; if (i < text.length() && text.charAt(i) == ':') { // handle seconds flexible i++; secs = Integer.valueOf(text.substring(i, i + 2)).intValue(); i += 2; } calendar.set(year, month, day, hour, mins, secs); calendar.set(Calendar.MILLISECOND, 0); // no parts of a second i = parseTZ(i, text); } catch (NumberFormatException ex) { pos.setErrorIndex(i); return null; } catch (IndexOutOfBoundsException ex) { pos.setErrorIndex(i); return null; } finally { pos.setIndex(i); } return calendar.getTime(); }
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.// www. j a va2s .c o m * * @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 ww . ja va 2 s . c om*/ 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);/* ww w . j a v a2 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);/*from w w w. j a v a 2 s .c o m*/ try { calendar.getTime(); } catch (IllegalArgumentException ie) { return getOutdatedCalendar(); } return calendar; }
From source file:org.kuali.coeus.s2sgen.impl.generate.support.NSFCoverPageBaseGenerator.java
/** * /* w w w . ja v a 2s . co m*/ * This method Converts the String that is passed to it into a calendar * object. The argument will be set as the Year in the Calendar Object. * * @param year - * The String value to be converted to Calendar Object * @return calendar value corresponding to the year(String) passed. */ public Calendar getYearAsCalendar(String year) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.DATE, 0); calendar.set(Calendar.MONTH, 0); try { calendar.set(Calendar.YEAR, Integer.parseInt(year)); } catch (NumberFormatException ex) { calendar.set(Calendar.YEAR, 0); } return calendar; }