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.linuxbox.enkive.teststats.StatsDayGrainTest.java
@BeforeClass public static void setUp() throws ParseException, GathererException { coll = TestHelper.GetTestCollection(); client = TestHelper.BuildClient();/*from ww w . j a va2 s . c o m*/ grain = new DayConsolidator(client); List<Map<String, Object>> stats = (new HourConsolidator(client)).consolidateData(); Map<String, Object> timeMap = new HashMap<String, Object>(); Calendar cal = Calendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 1); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.HOUR, 0); for (int i = 0; i < 10; i++) { if (i == 5) { cal.add(Calendar.DATE, -1); } timeMap.put(CONSOLIDATION_MAX, cal.getTime()); timeMap.put(CONSOLIDATION_MIN, cal.getTime()); for (Map<String, Object> data : stats) { data.put(STAT_TIMESTAMP, timeMap); } client.storeData(stats); } dataCount = coll.count(); }
From source file:helper.lang.DateHelperTest.java
@Test public void testAsUtcDayDate() { Calendar localTime = Calendar.getInstance(TimeZone.getTimeZone("CST")); Calendar cal = DateHelper.asUtcDay(localTime.getTime()); assertEquals(0, cal.get(Calendar.MILLISECOND)); assertEquals(0, cal.get(Calendar.MINUTE)); assertEquals(0, cal.get(Calendar.HOUR)); assertEquals(0, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(DateHelper.UTC_TIME_ZONE, cal.getTimeZone()); //assertEquals(TimeZone.getTimeZone("CST"), localTime.getTimeZone()); //assertEquals(localTime.get(Calendar.YEAR), cal.get(Calendar.YEAR)); //assertEquals(localTime.get(Calendar.MONTH), cal.get(Calendar.MONTH)); //assertEquals(localTime.get(Calendar.DATE), cal.get(Calendar.DATE)); }
From source file:com.autentia.common.util.DateFormater.java
public static Date normalizeInitDate(Date date) { GregorianCalendar gCalendar = new GregorianCalendar(); gCalendar.setTime(date);/* w w w . jav a 2 s. co m*/ gCalendar.set(Calendar.HOUR_OF_DAY, 0); gCalendar.set(Calendar.MINUTE, 0); gCalendar.set(Calendar.SECOND, 0); gCalendar.set(Calendar.MILLISECOND, 0); return gCalendar.getTime(); }
From source file:at.christophwurst.orm.service.BurnDownServiceImpl.java
private Date stripDate(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//from ww w . j av a2 s . com cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }
From source file:com.redhat.red.build.koji.model.json.util.SecondsSinceEpochDeserializer.java
@Override public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { long val = jp.getLongValue(); Calendar cal = Calendar.getInstance(); cal.setTime(new Date(val * 1000L)); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }
From source file:com.linuxbox.enkive.teststats.StatsWeekGrainTest.java
@BeforeClass public static void setUp() throws ParseException, GathererException { coll = TestHelper.GetTestCollection(); client = TestHelper.BuildClient();//from w w w .ja v a 2 s. com grain = new WeekConsolidator(client); List<Map<String, Object>> stats = (new DayConsolidator(client)).consolidateData(); Map<String, Object> timeMap = createMap(); Calendar cal = Calendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.HOUR, 0); for (int i = 0; i < 10; i++) { if (i == 5) { cal.add(Calendar.WEEK_OF_MONTH, -1); } timeMap.put(CONSOLIDATION_MAX, cal.getTime()); timeMap.put(CONSOLIDATION_MIN, cal.getTime()); for (Map<String, Object> data : stats) { data.put(STAT_TIMESTAMP, timeMap); } client.storeData(stats); } dataCount = coll.count(); }
From source file:com.ar.dev.tierra.api.dao.impl.ChartDAOImpl.java
@SuppressWarnings("unchecked") @Override/*www .jav a 2 s . c o m*/ public List<Chart> getVentaVendedores(int idVendedor) { Calendar calendarInitial = Calendar.getInstance(); Calendar calendarClosing = Calendar.getInstance(); calendarInitial.set(Calendar.HOUR_OF_DAY, 0); calendarInitial.set(Calendar.MINUTE, 0); calendarInitial.set(Calendar.SECOND, 0); calendarInitial.set(Calendar.MILLISECOND, 0); Date fromDate = calendarInitial.getTime(); calendarClosing.set(Calendar.HOUR_OF_DAY, 23); calendarClosing.set(Calendar.MINUTE, 59); calendarClosing.set(Calendar.SECOND, 59); calendarClosing.set(Calendar.MILLISECOND, 59); Date toDate = calendarClosing.getTime(); int days = 0; List<Chart> chartVenta = new ArrayList<>(); while (days <= 6) { Chart chart = new Chart(); Criteria facturas = getSession().createCriteria(Factura.class); facturas.add(Restrictions.like("estado", "CONFIRMADO")); facturas.add(Restrictions.between("fechaCreacion", fromDate, toDate)); Criteria vendedorFactura = facturas.createCriteria("idVendedor"); vendedorFactura.add(Restrictions.eq("idUsuario", idVendedor)); vendedorFactura.setProjection(Projections.rowCount()); Long counter = (Long) facturas.uniqueResult(); chart.setValue(counter.intValue()); chart.setDate(fromDate); chartVenta.add(chart); calendarInitial.add(Calendar.DAY_OF_MONTH, -1); fromDate = calendarInitial.getTime(); calendarClosing.add(Calendar.DAY_OF_MONTH, -1); toDate = calendarClosing.getTime(); days++; } return chartVenta; }
From source file:com.adobe.acs.commons.http.headers.impl.DailyExpiresHeaderFilterTest.java
@Test public void testAdjustExpiresFuture() throws Exception { Calendar actual = Calendar.getInstance(); actual.add(Calendar.MINUTE, 1); actual.set(Calendar.SECOND, 0); actual.set(Calendar.MILLISECOND, 0); Calendar expected = Calendar.getInstance(); expected.setTime(actual.getTime());/*from w w w . j a va 2 s. c om*/ filter.adjustExpires(actual); assertTrue(DateUtils.isSameInstant(expected, actual)); }
From source file:Main.java
/** * Parses an xs:dateTime attribute value, returning the parsed timestamp in milliseconds since * the epoch.// w ww . j av a 2 s . c o m * * @param value The attribute value to parse. * @return The parsed timestamp in milliseconds since the epoch. */ public static long parseXsDateTime(String value) throws ParseException { Matcher matcher = XS_DATE_TIME_PATTERN.matcher(value); if (!matcher.matches()) { throw new ParseException("Invalid date/time format: " + value, 0); } int timezoneShift; if (matcher.group(9) == null) { // No time zone specified. timezoneShift = 0; } else if (matcher.group(9).equalsIgnoreCase("Z")) { timezoneShift = 0; } else { timezoneShift = ((Integer.parseInt(matcher.group(12)) * 60 + Integer.parseInt(matcher.group(13)))); if (matcher.group(11).equals("-")) { timezoneShift *= -1; } } Calendar dateTime = new GregorianCalendar(TimeZone.getTimeZone("GMT")); dateTime.clear(); // Note: The month value is 0-based, hence the -1 on group(2) dateTime.set(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)) - 1, Integer.parseInt(matcher.group(3)), Integer.parseInt(matcher.group(4)), Integer.parseInt(matcher.group(5)), Integer.parseInt(matcher.group(6))); if (!TextUtils.isEmpty(matcher.group(8))) { final BigDecimal bd = new BigDecimal("0." + matcher.group(8)); // we care only for milliseconds, so movePointRight(3) dateTime.set(Calendar.MILLISECOND, bd.movePointRight(3).intValue()); } long time = dateTime.getTimeInMillis(); if (timezoneShift != 0) { time -= timezoneShift * 60000; } return time; }
From source file:DateUtils.java
public static String getTimestamp() { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); int hours = cal.get(Calendar.HOUR_OF_DAY); // use 24 hour clock int minutes = cal.get(Calendar.MINUTE); int seconds = cal.get(Calendar.SECOND); int milli = cal.get(Calendar.MILLISECOND); return "" + year + "-" + month + "-" + day + "_" + formatTime(hours, minutes, seconds, milli); }