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:org.testeditor.dashboard.TableDurationTrend.java
/** * Formatting duration(ms) in h:m:s:ms./* w w w. ja v a 2 s . com*/ * * @param number * for time formatting * @return durationFormat */ private String formatDuration(double number) { // TODO: refactor - see formatDuration in MyLabelProvider Time time = new Time((long) number); Calendar cal = Calendar.getInstance(); cal.setTime(time); String durationFormat = cal.get(Calendar.HOUR) - 1 + "h:" + cal.get(Calendar.MINUTE) + "m:" + cal.get(Calendar.SECOND) + "s:" + cal.get(Calendar.MILLISECOND) + "ms"; return durationFormat; }
From source file:com.labs64.utils.swid.support.JAXBUtils.java
/** * Convert {@link Date} to {@link XMLGregorianCalendar}. * //from www .jav a 2 s . c om * @param date * XML entity */ public static XMLGregorianCalendar convertDateToXMLGregorianCalendar(final Date date) { try { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date); XMLGregorianCalendar calXml = DatatypeFactory.newInstance().newXMLGregorianCalendar( cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), cal.get(Calendar.MILLISECOND), 0); return calXml; } catch (DatatypeConfigurationException e) { throw new SwidException("Cannot convert date", e); } }
From source file:eionet.meta.service.SiteCodeServiceImpl.java
/** * {@inheritDoc}/*from ww w.j a v a 2 s. c o m*/ */ @Override public AllocationResult allocateSiteCodes(String countryCode, String[] siteNames, String userName) throws ServiceException { int amount = siteNames.length; SiteCodeFilter siteCodeFilter = new SiteCodeFilter(); siteCodeFilter.setPageNumber(1); siteCodeFilter.setPageSize(amount); siteCodeFilter.setStatus(SiteCodeStatus.AVAILABLE); try { SiteCodeResult freeSiteCodes = siteCodeDao.searchSiteCodes(siteCodeFilter); Calendar c = Calendar.getInstance(); c.set(Calendar.MILLISECOND, 0); Date allocationTime = c.getTime(); if (freeSiteCodes.getList().size() != amount) { throw new ServiceException( "Did not find enough free site codes for allocating " + amount + " sites!"); } siteCodeDao.allocateSiteCodes(freeSiteCodes.getList(), countryCode, userName, siteNames, allocationTime); AllocationResult result = new AllocationResult(); result.setAmount(amount); result.setUserName(userName); result.setAllocationTime(allocationTime); LOGGER.info( userName + " allocated " + amount + " site codes for " + countryCode + " on " + allocationTime); return result; } catch (Exception e) { throw new ServiceException("Failed to allocate site codes: " + e.getMessage(), e); } }
From source file:com.indoqa.lang.util.TimeUtilsTest.java
@Test public void getStartOfDay() { final DateFormat timeInstance = new SimpleDateFormat("HH:mm:ss.SSS"); final Random random = new Random(); Calendar calendar = Calendar.getInstance(); for (int i = 0; i < 10; i++) { calendar.add(Calendar.MILLISECOND, random.nextInt(1000000)); assertEquals("Failed to calculate start of day for date with long value " + calendar.getTimeInMillis(), "00:00:00.000", timeInstance.format(TimeUtils.getStartOfDay(calendar.getTime()))); }/*w ww. java2 s. c o m*/ timeInstance.setTimeZone(TimeZone.getTimeZone("UTC")); assertEquals("22:00:00.000", timeInstance.format(TimeUtils.getStartOfDay(new Date(), TimeZone.getTimeZone("GMT+2")))); assertEquals("01:00:00.000", timeInstance.format(TimeUtils.getStartOfDay(new Date(), TimeZone.getTimeZone("GMT-1")))); }
From source file:com.bsg.pcms.provision.contract.ContractDaoTest.java
public java.sql.Date getSQLDate() { java.util.Date utilDate = new java.util.Date(); // your util date java.util.Calendar cal = Calendar.getInstance(); cal.setTime(utilDate);// www. j a va2 s .c o m cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); java.sql.Date sqlDate = new java.sql.Date(cal.getTime().getTime()); // your sql date logger.info("utilDate:" + utilDate); logger.info("sqlDate:" + sqlDate); return sqlDate; }
From source file:org.eevolution.form.CRP.java
/** * Create Category Dataset based on date start and resource * @param start/* w w w. ja v a 2 s . co m*/ * @param resource * @return CategoryDataset */ protected CategoryDataset createDataset(Timestamp start, MResource resource) { GregorianCalendar gc1 = new GregorianCalendar(); gc1.setTimeInMillis(start.getTime()); gc1.clear(Calendar.MILLISECOND); gc1.clear(Calendar.SECOND); gc1.clear(Calendar.MINUTE); gc1.clear(Calendar.HOUR_OF_DAY); Timestamp date = start; String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); String nameload = Msg.translate(Env.getCtx(), "Load"); String namesummary = Msg.translate(Env.getCtx(), "Summary"); MResourceType t = MResourceType.get(Env.getCtx(), resource.getS_ResourceType_ID()); int days = 1; long hours = t.getTimeSlotHours(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Long Hours = new Long(hours); int C_UOM_ID = DB.getSQLValue(null, "SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? ", resource.getS_Resource_ID()); MUOM uom = MUOM.get(Env.getCtx(), C_UOM_ID); if (!uom.isHour()) { return dataset; } long summary = 0; while (days < 32) { String day = new String(new Integer(date.getDate()).toString()); long HoursLoad = getLoad(resource, date).longValue(); Long Hours = new Long(hours); switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: days++; if (t.isOnSunday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.MONDAY: days++; if (t.isOnMonday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.TUESDAY: days++; if (t.isOnTuesday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.WEDNESDAY: days++; if (t.isOnWednesday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.THURSDAY: days++; if (t.isOnThursday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.FRIDAY: days++; if (t.isOnFriday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.SATURDAY: days++; if (t.isOnSaturday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } } } return dataset; }
From source file:com.haulmont.cuba.gui.components.data.DataAwareComponentsTools.java
public void setupDateRange(HasRange component, EntityValueSource valueSource) { MetaProperty metaProperty = valueSource.getMetaPropertyPath().getMetaProperty(); // FIXME: gg, replace with LocalDateTime? if (metaProperty.getAnnotations().get(Past.class.getName()) != null) { Date currentTimestamp = timeSource.currentTimestamp(); Calendar calendar = Calendar.getInstance(sessionSource.getLocale()); calendar.setTime(currentTimestamp); calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); calendar.set(Calendar.MILLISECOND, 999); component.setRangeEnd(calendar.getTime()); } else if (metaProperty.getAnnotations().get(Future.class.getName()) != null) { Date currentTimestamp = timeSource.currentTimestamp(); Calendar calendar = Calendar.getInstance(sessionSource.getLocale()); calendar.setTime(currentTimestamp); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.add(Calendar.DATE, 1); component.setRangeStart(calendar.getTime()); }/* w w w . ja va2 s. c o m*/ }
From source file:DateUtil.java
public static Date getEndOfHour(Date day, Calendar cal) { if (day == null || cal == null) { return day; }/*from w ww. j a v a2 s.c o m*/ cal.setTime(day); cal.set(Calendar.MINUTE, cal.getMaximum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND)); return cal.getTime(); }
From source file:com.consol.citrus.samples.incident.service.IncidentManagerService.java
/** * Gets the default next schedule time which is current timestamp +1h with * normalized minutes and seconds./* w w w . j ava 2 s . c o m*/ * * @return */ private Calendar getScheduledTime() { Calendar scheduled = Calendar.getInstance(); scheduled.add(Calendar.HOUR, 1); scheduled.set(Calendar.MINUTE, 0); scheduled.set(Calendar.SECOND, 0); scheduled.set(Calendar.MILLISECOND, 0); return scheduled; }
From source file:com.terradue.jcatalogue.client.internal.converters.AtomDateConverter.java
public Object convert(@SuppressWarnings("rawtypes") Class type, Object value) { if (value == null) { throw new ConversionException("Null values not supported in this version."); }/*from w ww .j ava2 s .c om*/ if (String.class == type) { if (value instanceof Date) { StringBuilder sb = new StringBuilder(); Calendar c = getInstance(getTimeZone("GMT")); c.setTime((Date) value); sb.append(c.get(YEAR)); sb.append('-'); int f = c.get(MONTH); if (f < 9) sb.append('0'); sb.append(f + 1); sb.append('-'); f = c.get(DATE); if (f < 10) sb.append('0'); sb.append(f); sb.append('T'); f = c.get(HOUR_OF_DAY); if (f < 10) sb.append('0'); sb.append(f); sb.append(':'); f = c.get(MINUTE); if (f < 10) sb.append('0'); sb.append(f); sb.append(':'); f = c.get(SECOND); if (f < 10) sb.append('0'); sb.append(f); sb.append('.'); f = c.get(MILLISECOND); if (f < 100) sb.append('0'); if (f < 10) sb.append('0'); sb.append(f); sb.append('Z'); return sb.toString(); } } else if (Date.class == type) { if (value instanceof String) { Matcher m = PATTERN.matcher((String) value); if (m.find()) { Calendar c = Calendar.getInstance(getTimeZone("GMT")); int hoff = 0, moff = 0, doff = -1; if (m.group(9) != null) { doff = m.group(9).equals("-") ? 1 : -1; hoff = doff * (m.group(10) != null ? Integer.parseInt(m.group(10)) : 0); moff = doff * (m.group(11) != null ? Integer.parseInt(m.group(11)) : 0); } c.set(Calendar.YEAR, Integer.parseInt(m.group(1))); c.set(Calendar.MONTH, m.group(2) != null ? Integer.parseInt(m.group(2)) - 1 : 0); c.set(Calendar.DATE, m.group(3) != null ? Integer.parseInt(m.group(3)) : 1); c.set(Calendar.HOUR_OF_DAY, m.group(4) != null ? Integer.parseInt(m.group(4)) + hoff : 0); c.set(Calendar.MINUTE, m.group(5) != null ? Integer.parseInt(m.group(5)) + moff : 0); c.set(Calendar.SECOND, m.group(6) != null ? Integer.parseInt(m.group(6)) : 0); c.set(Calendar.MILLISECOND, m.group(7) != null ? Integer.parseInt(m.group(7)) : 0); return c.getTime(); } throw new IllegalArgumentException("Invalid Date Format"); } } throw new ConversionException(format("type %s and value %s not supported", type, value)); }