Example usage for java.util Calendar MILLISECOND

List of usage examples for java.util Calendar MILLISECOND

Introduction

In this page you can find the example usage for java.util Calendar MILLISECOND.

Prototype

int MILLISECOND

To view the source code for java.util Calendar MILLISECOND.

Click Source Link

Document

Field number for get and set indicating the millisecond within the second.

Usage

From source file:Main.java

public static Date getDateTimeFrom(Date iDate, int mode, int adddate) {

    Calendar calendar = Calendar.getInstance();
    Calendar calendarDate = Calendar.getInstance();
    calendarDate.setTime(iDate);//w ww .  j  av  a 2 s.c  om

    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    switch (mode) {

    case Calendar.DAY_OF_MONTH: {
        calendar.set(Calendar.DAY_OF_MONTH, calendarDate.get(Calendar.DAY_OF_MONTH) + adddate);
    }
        break;

    }
    Date ret = calendar.getTime();
    Log.v("!!!!!!!!!! calendar=", "" + ret);

    return ret;
}

From source file:com.qpark.eip.core.spring.statistics.dao.StatisticsLoggingDao.java

/**
 * Get a {@link Date}, where hours, minutes, seconds and milliseconds are
 * set to 0.// w  w w .ja v a  2 s. c o m
 *
 * @return the {@link Date} .
 */
private static Date getDayEnd(final Date d) {
    final Calendar gc = new GregorianCalendar(LOGGING_TIMEZONE);
    gc.setTime(d);
    gc.set(Calendar.HOUR_OF_DAY, 23);
    gc.set(Calendar.MINUTE, 59);
    gc.set(Calendar.SECOND, 59);
    gc.set(Calendar.MILLISECOND, 0);
    return gc.getTime();
}

From source file:CalendarDemo.java

public void format() {

    // Tell the calendar what date/time to format
    calendar.setTime(timeNow);/*from  www.ja v  a  2s.c  o m*/

    // print out most of the known fields
    System.out.println("ERA: " + calendar.get(Calendar.ERA));
    System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
    System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
    System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
    System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
    System.out.println("DATE: " + calendar.get(Calendar.DATE));
    System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
    System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
    System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
    System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
    System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
    System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
    System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
    System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
    System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
    System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)));
    System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000)));
}

From source file:com.autentia.common.util.DateFormater.java

public static Date normalizeEndDate(Date date) {

    GregorianCalendar gCalendar = new GregorianCalendar();
    gCalendar.setTime(date);/*from  w  ww.  ja  v  a2  s  . c om*/
    gCalendar.set(Calendar.HOUR_OF_DAY, 23);
    gCalendar.set(Calendar.MINUTE, 59);
    gCalendar.set(Calendar.SECOND, 59);
    gCalendar.set(Calendar.MILLISECOND, 999);

    return gCalendar.getTime();
}

From source file:org.openmrs.module.openconceptlab.scheduler.UpdateScheduler.java

@SuppressWarnings("unchecked")
public synchronized void schedule(Subscription subscription) {
    updateService.saveSubscription(subscription);

    if (scheduledUpdate != null) {
        scheduledUpdate.cancel(false);//from w  w w  . j a  v a 2  s  . c o m
    }

    if (subscription.getDays() != 0 || subscription.getHours() != 0 || subscription.getMinutes() != 0) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, subscription.getHours());
        calendar.set(Calendar.MINUTE, subscription.getMinutes());
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        scheduledUpdate = scheduler.scheduleAtFixedRate(updater, calendar.getTime(),
                subscription.getDays() * DAY_PERIOD);
    }
}

From source file:org.kuali.coeus.s2sgen.impl.datetime.S2SDateTimeServiceImpl.java

/**
 *
 * This method computes the number of months between any 2 given {@link java.sql.Date} objects
 *
 * @param dateStart starting date./*from w w w  .  j  a v  a  2s .  co  m*/
 * @param dateEnd end date.
 *
 * @return number of months between the start date and end date.
 */
@Override
public ScaleTwoDecimal getNumberOfMonths(java.util.Date dateStart, java.util.Date dateEnd) {
    ScaleTwoDecimal monthCount = ScaleTwoDecimal.ZERO;
    int fullMonthCount = 0;

    Calendar startDate = Calendar.getInstance();
    Calendar endDate = Calendar.getInstance();
    startDate.setTime(dateStart);
    endDate.setTime(dateEnd);

    startDate.clear(Calendar.HOUR);
    startDate.clear(Calendar.MINUTE);
    startDate.clear(Calendar.SECOND);
    startDate.clear(Calendar.MILLISECOND);

    endDate.clear(Calendar.HOUR);
    endDate.clear(Calendar.MINUTE);
    endDate.clear(Calendar.SECOND);
    endDate.clear(Calendar.MILLISECOND);

    if (startDate.after(endDate)) {
        return ScaleTwoDecimal.ZERO;
    }
    int startMonthDays = startDate.getActualMaximum(Calendar.DATE) - startDate.get(Calendar.DATE);
    startMonthDays++;
    int startMonthMaxDays = startDate.getActualMaximum(Calendar.DATE);
    BigDecimal startMonthFraction = BigDecimal.valueOf(startMonthDays).setScale(2, RoundingMode.HALF_UP).divide(
            BigDecimal.valueOf(startMonthMaxDays).setScale(2, RoundingMode.HALF_UP), RoundingMode.HALF_UP);

    int endMonthDays = endDate.get(Calendar.DATE);
    int endMonthMaxDays = endDate.getActualMaximum(Calendar.DATE);

    BigDecimal endMonthFraction = BigDecimal.valueOf(endMonthDays).setScale(2, RoundingMode.HALF_UP).divide(
            BigDecimal.valueOf(endMonthMaxDays).setScale(2, RoundingMode.HALF_UP), RoundingMode.HALF_UP);

    startDate.set(Calendar.DATE, 1);
    endDate.set(Calendar.DATE, 1);

    while (startDate.getTimeInMillis() < endDate.getTimeInMillis()) {
        startDate.set(Calendar.MONTH, startDate.get(Calendar.MONTH) + 1);
        fullMonthCount++;
    }
    fullMonthCount = fullMonthCount - 1;
    monthCount = monthCount.add(new ScaleTwoDecimal(fullMonthCount))
            .add(new ScaleTwoDecimal(startMonthFraction)).add(new ScaleTwoDecimal(endMonthFraction));
    return monthCount;
}

From source file:org.openmrs.module.rwandaprimarycare.AllEncountersController.java

@RequestMapping("/module/rwandaprimarycare/allEncounters")
public String listAllEncounters(@RequestParam("patientId") int patientId, ModelMap model)
        throws PrimaryCareException {

    //LK: Need to ensure that all primary care methods only throw a PrimaryCareException
    //So that errors will be directed to a touch screen error page
    try {/*w w  w.  j av a  2s  .c  om*/
        Patient patient = Context.getPatientService().getPatient(patientId);
        SortedMap<Date, List<Encounter>> encounters = new TreeMap<Date, List<Encounter>>(
                Collections.reverseOrder());
        for (Encounter e : Context.getEncounterService().getEncountersByPatient(patient)) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(e.getEncounterDatetime());
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MILLISECOND, 0);
            Date day = cal.getTime();
            List<Encounter> holder = encounters.get(day);
            if (holder == null) {
                holder = new ArrayList<Encounter>();
                encounters.put(day, holder);
            }
            holder.add(e);
        }
        model.addAttribute("patient", patient);
        model.addAttribute("encounters", encounters);
        model.addAttribute("vitalsEncounterType", PrimaryCareBusinessLogic.getVitalsEncounterType());
        model.addAttribute("registrationEncounterType",
                PrimaryCareBusinessLogic.getRegistrationEncounterType());
    } catch (Exception e) {
        throw new PrimaryCareException(e);
    }
    return "/module/rwandaprimarycare/allEncounters";
}

From source file:be.boyenvaesen.scheduling.HumiditySchedules.java

@Scheduled(fixedRate = 2000)
public void updateIntervalDatabases() {
    log.info("Starting database cleanup");

    Calendar c = Calendar.getInstance();
    Calendar calForCalculations = Calendar.getInstance();
    //Clean records dating till :
    c.add(Calendar.HOUR, -5);/* w ww.j  ava  2  s .com*/
    Date now = new Date();

    List<Humidity> allHumidities = service.getBetweenDates(c.getTime(), now);
    List<HumidityByMinute> humiditiesByMinute = service.getBetweenDatesByInterval(HumidityByMinute.class,
            c.getTime(), now);
    List<HumidityByHour> humidityByHour = service.getBetweenDatesByInterval(HumidityByHour.class, c.getTime(),
            now);

    //Group humidities by minute
    Map<Date, List<Humidity>> map = allHumidities.stream().collect(Collectors.groupingBy((t) -> {

        calForCalculations.setTime(t.getMeasured());
        calForCalculations.set(Calendar.SECOND, 0);
        calForCalculations.set(Calendar.MILLISECOND, 0);

        return calForCalculations.getTime();
    }));
    //CALCULATE MINUTES
    map.forEach((t, u) -> {
        HumidityByMinute toCalc = humiditiesByMinute.stream().filter((q) -> {
            return q.getAtTime().compareTo(t) == 0;
        }).findAny().orElse(new HumidityByMinute(t));
        float average = (float) u.stream().mapToDouble(Humidity::getPercentage).average().getAsDouble();
        toCalc.setAveragePercentage(average);
        service.saveByInterval(toCalc);
    });

    List<HumidityByMinute> newByMinute = service.getBetweenDatesByInterval(HumidityByMinute.class, c.getTime(),
            now);
    //Group HumidityByMinute By hour
    Map<Date, List<HumidityByMinute>> mapByHour = newByMinute.stream().collect(Collectors.groupingBy((t) -> {
        calForCalculations.setTime(t.getAtTime());
        calForCalculations.set(Calendar.MINUTE, 0);
        return calForCalculations.getTime();
    }));
    //CALCULATE HOURS
    mapByHour.forEach((t, u) -> {

        HumidityByHour toCalc = humidityByHour.stream().filter((q) -> {
            return q.getAtTime().compareTo(t) == 0;
        }).findAny().orElse(new HumidityByHour(t));
        float average = (float) u.stream().mapToDouble(HumidityByMinute::getAveragePercentage).average()
                .getAsDouble();
        toCalc.setAveragePercentage(average);
        service.saveByInterval(toCalc);

    });
    log.info("finished cleaning database");

}

From source file:br.com.itfox.utils.Utils.java

public static Timestamp dateToTimestamp(Date utilDate) {
    long millis = DateUtils.truncate(utilDate, Calendar.MILLISECOND).getTime();
    java.sql.Timestamp sq = new java.sql.Timestamp(millis);
    return sq;// w w w  .  j ava2 s.co  m
}

From source file:org.tsm.concharto.dao.IntegrationTestEventDao.java

@Before
public void setUp() {
    Calendar cal = new GregorianCalendar(107 + 1900, 8, 22, 12, 22, 3);
    cal.set(Calendar.MILLISECOND, 750);
    begin = cal.getTime();//w w  w.j a v a 2 s .c o m
    cal.set(Calendar.SECOND, 35);
    end = cal.getTime();
    getEventTesterDao().deleteAll();
}