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:uk.org.funcube.fcdw.server.processor.WholeOrbitDataProcessorImpl.java

@Override
@Transactional(readOnly = false)/*from w  w  w  .  j a  v a2s .c o m*/
public void process(long satelliteId) {
    Calendar cal = Calendar.getInstance(TZ);
    cal.add(Calendar.HOUR, -24);

    final List<HexFrameEntity> wodList = hexFrameDao.findUnprocessedWOD(satelliteId, cal.getTime());

    LOG.debug("Found: " + wodList.size() + " unprocessed wod frames");

    long oldSeqNo = -1;

    List<String> frames = new ArrayList<String>();

    List<HexFrameEntity> processedHexFrames = new ArrayList<HexFrameEntity>();

    Date receivedDate = null;

    for (final HexFrameEntity wodFrame : wodList) {
        if (wodFrame.getFrameType() == 11) {
            receivedDate = wodFrame.getCreatedDate();
        }
        if (wodFrame.getSequenceNumber() != oldSeqNo) {
            if (oldSeqNo != -1) {
                if (frames.size() == 12) {

                    cal = Calendar.getInstance(TZ);
                    cal.setTime(receivedDate);
                    cal.set(Calendar.SECOND, 0);
                    cal.set(Calendar.MILLISECOND, 0);
                    receivedDate = cal.getTime();

                    extractAndSaveWod(satelliteId, oldSeqNo, frames, receivedDate);

                    for (HexFrameEntity hfe : processedHexFrames) {
                        hfe.setHighPrecisionProcessed(true);
                        hexFrameDao.save(hfe);
                    }
                }
                frames = new ArrayList<String>();
                processedHexFrames = new ArrayList<HexFrameEntity>();
                frames.add(wodFrame.getHexString().substring(106, wodFrame.getHexString().length()));
                processedHexFrames.add(wodFrame);
            }

            oldSeqNo = wodFrame.getSequenceNumber();
        } else {
            frames.add(wodFrame.getHexString().substring(106, wodFrame.getHexString().length()));
            processedHexFrames.add(wodFrame);
        }
    }

}

From source file:hd3gtv.mydmam.db.orm.AutotestOrm.java

public static AutotestOrm populate(int index) {
    AutotestOrm result = new AutotestOrm();

    result.key = "THISISMYKEY" + String.valueOf(index);
    result.strvalue = "Hello world with cnts";
    result.bytvalue = result.strvalue.toUpperCase().getBytes();
    result.intvalue = 42;//from   ww w. j ava  2 s. c o m
    result.lngvalue = -3329447494103907027L;
    result.bolvalue = true;
    result.fltvalue = 6.55957f;
    result.dlbvalue = (double) result.lngvalue / 11d;
    result.uuivalue = UUID.fromString("110E8400-E29B-11D4-A716-446655440000");
    result.jsovalue = new JSONObject();
    result.jsovalue.put("Hello", "world");
    result.jsovalue.put("Count", index);
    result.jsavalue = new JSONArray();
    result.jsavalue.add("One");
    result.jsavalue.add(42);
    result.jsavalue.add("Un");
    try {
        result.addressvalue = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    result.sbuvalue = new StringBuffer();
    result.sbuvalue.append(result.key);
    result.sbuvalue.append(result.strvalue);
    result.sbuvalue.append(result.lngvalue);
    result.calendarvalue = Calendar.getInstance();
    result.calendarvalue.set(1995, 05, 23, 10, 04, 8);
    result.calendarvalue.set(Calendar.MILLISECOND, 666);
    result.dtevalue = result.calendarvalue.getTime();
    result.strarrayvalue = new String[2];
    result.strarrayvalue[0] = result.strvalue;
    result.strarrayvalue[1] = result.key;
    result.serializvalue = new HashMap<String, String>();
    result.serializvalue.put("Some var", result.strvalue);
    result.serializvalue.put("Other var", result.uuivalue.toString());

    result.enumvalue = MyEnum.ME;

    result.iamempty = "";
    result.iamanindex = index;
    result.donttouchme = "F*ck you";
    return result;
}

From source file:Main.java

/**
 *
 * This method is a utility method to create a new java.sql.Date in one line.
 *
 * @param year//  w  w  w . j  a va2  s .c  om
 * @param month
 * @param day
 * @param hour
 * @param minute
 * @param second
 *
 * @return a populated java.sql.Date with the year, month, hour, minute, and second populated, with no value for millisecond.
 *
 */
public static java.sql.Date newDate(Integer year, Integer month, Integer day, Integer hour, Integer minute,
        Integer second) {

    // test for null arguments
    if (year == null) {
        throw new IllegalArgumentException("Argument 'year' passed in was null.");
    }
    if (month == null) {
        throw new IllegalArgumentException("Argument 'month' passed in was null.");
    }
    if (day == null) {
        throw new IllegalArgumentException("Argument 'day' passed in was null.");
    }
    if (hour == null) {
        throw new IllegalArgumentException("Argument 'hour' passed in was null.");
    }
    if (minute == null) {
        throw new IllegalArgumentException("Argument 'minute' passed in was null.");
    }
    if (second == null) {
        throw new IllegalArgumentException("Argument 'second' passed in was null.");
    }

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month);
    calendar.set(Calendar.DAY_OF_MONTH, day);
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, second);
    calendar.clear(Calendar.MILLISECOND);

    return new java.sql.Date(calendar.getTimeInMillis());
}

From source file:com.linuxbox.enkive.teststats.StatsMonthGrainTest.java

@BeforeClass
public static void setUp() throws ParseException, GathererException {
    coll = TestHelper.GetTestCollection();
    client = TestHelper.BuildClient();// ww  w. j av a  2s.c  o  m
    grain = new MonthConsolidator(client);

    // clean up if week was run...
    Map<String, Object> queryMap = new HashMap<String, Object>();
    queryMap.put(CONSOLIDATION_TYPE, CONSOLIDATION_DAY);
    StatsQuery statsQuery = new MongoStatsQuery(null, CONSOLIDATION_DAY, null);
    Set<Object> ids = new HashSet<Object>();
    for (Map<String, Object> mapToDelete : client.queryStatistics(statsQuery)) {
        ids.add(mapToDelete.get("_id"));
    }

    if (!ids.isEmpty()) {
        client.remove(ids);
    }

    // TODO
    List<Map<String, Object>> stats = (new DayConsolidator(client)).consolidateData();
    Map<String, Object> timeMap = new HashMap<String, Object>();
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    for (int i = 0; i < 10; i++) {
        if (i == 5) {
            cal.add(Calendar.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:gov.nasa.arc.spife.ui.table.days.Day.java

private static TemporalExtent computeDayExtent(Date start) {
    Date end;/*from   w w  w.  j a  v a  2 s . c  o m*/
    synchronized (CALENDAR) {
        CALENDAR.setTime(start);
        CALENDAR.add(Calendar.DAY_OF_YEAR, 1);
        CALENDAR.add(Calendar.MILLISECOND, -1);
        end = CALENDAR.getTime();
    }
    return new TemporalExtent(start, end);
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.util.DateUtils.java

/**
 * Checks if the date represented by the passed parameters is valid.
 * All parameters are 1-based meaning 1 for Jan, 2 for Feb etc unlike Java Calendar API
 *
 * @param day date value for the date (1-based)
 * @param month month value for the date (1-based)
 * @param year year value for the date (1-based)
 * @return  the <code>Date</code> if valid, <code>null</code> otherwise
 * @throws DateUtilsException if the date does not have the expected format
 *//*from   www .j ava 2  s  .  co  m*/
public static Date validate(final String day, final String month, final String year) throws DateUtilsException {

    Date result = null;

    if (validateDateFormat(day, month, year)) {

        final Calendar cal = Calendar.getInstance();
        cal.setLenient(false);
        cal.set(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day), 0, 0, 0);
        cal.set(Calendar.MILLISECOND, 0);

        try {
            //Important : getTime has to be called to find out that the date is correct.
            result = cal.getTime();

        } catch (IllegalArgumentException e) {
            // this exception is thrown by the Java Calender getTime Method, if the date is not valid
        }
    }

    return result;
}

From source file:TimeLib.java

/**
 * Based on code posted at/*from w  w  w .  ja  v a2s  . c o  m*/
 *  http://forum.java.sun.com/thread.jspa?threadID=488676&messageID=2292012
 */
private static int estimateUnitsBetween(long t0, long t1, int field) {
    long d = t1 - t0;
    switch (field) {
    case Calendar.MILLISECOND:
        return (int) d; // this could be very inaccurate. TODO: use long instead of int?
    case Calendar.SECOND:
        return (int) (d / SECOND_MILLIS + .5);
    case Calendar.MINUTE:
        return (int) (d / MINUTE_MILLIS + .5);
    case Calendar.HOUR_OF_DAY:
    case Calendar.HOUR:
        return (int) (d / HOUR_MILLIS + .5);
    case Calendar.DAY_OF_WEEK_IN_MONTH:
    case Calendar.DAY_OF_MONTH:
        // case Calendar.DATE : // codes to same int as DAY_OF_MONTH
        return (int) (d / DAY_MILLIS + .5);
    case Calendar.WEEK_OF_YEAR:
        return (int) (d / WEEK_MILLIS + .5);
    case Calendar.MONTH:
        return (int) (d / MONTH_MILLIS + .5);
    case Calendar.YEAR:
        return (int) (d / YEAR_MILLIS + .5);
    case DECADE:
        return (int) (d / DECADE_MILLIS + .5);
    case CENTURY:
        return (int) (d / CENTURY_MILLIS + .5);
    case MILLENIUM:
        return (int) (d / MILLENIUM_MILLIS + .5);
    default:
        return 0;
    }
}

From source file:com.clustercontrol.maintenance.factory.MaintenanceObject.java

/**
 * ?(dataRetentionPeriod)????00:00:00?epoch()??
 * @param dataRetentionPeriod//from www  .j  a  v  a 2  s.  co m
 * @return
 */
private Long getDataRetentionBoundary(int dataRetentionPeriod) {
    m_log.debug("getDataRetentionBoundary() dataRetentionPeriod : " + dataRetentionPeriod);

    // ???
    Calendar calendar = HinemosTime.getCalendarInstance();

    // 0?dataRetentionPeriod????
    if (dataRetentionPeriod > 0) {
        calendar.add(Calendar.DATE, -dataRetentionPeriod);
    }
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    Long boundary = calendar.getTimeInMillis();

    m_log.debug("getDataRetentionBoundary() : boundary is " + boundary + " ("
            + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(boundary) + ")");

    return boundary;
}

From source file:DateUtility.java

public static Date parseW3CDTFDate(String dateString) {
    Matcher m = null;//from  ww  w.j ava  2  s  . co m
    if ((m = W3CDTF_FORMAT1.matcher(dateString)).matches()) {
        TimeZone tz;
        if ("Z".equals(m.group(7))) {
            tz = TimeZone.getTimeZone("GMT+00:00");
        } else {
            tz = TimeZone.getTimeZone("GMT" + m.group(7));
        }
        Calendar c = Calendar.getInstance(tz);
        int year = Integer.parseInt(m.group(1));
        int month = Integer.parseInt(m.group(2)) - 1;
        int date = Integer.parseInt(m.group(3));
        int hour = Integer.parseInt(m.group(4));
        int minute = Integer.parseInt(m.group(5));
        int second = Integer.parseInt(m.group(6));
        c.set(year, month, date, hour, minute, second);
        c.set(Calendar.MILLISECOND, 0);
        return c.getTime();
    }
    if ((m = W3CDTF_FORMAT2.matcher(dateString)).matches()) {
        TimeZone tz;
        if ("Z".equals(m.group(6))) {
            tz = TimeZone.getTimeZone("GMT+00:00");
        } else {
            tz = TimeZone.getTimeZone("GMT" + m.group(6));
        }
        Calendar c = Calendar.getInstance(tz);
        int year = Integer.parseInt(m.group(1));
        int month = Integer.parseInt(m.group(2)) - 1;
        int date = Integer.parseInt(m.group(3));
        int hour = Integer.parseInt(m.group(4));
        int minute = Integer.parseInt(m.group(5));
        c.set(year, month, date, hour, minute, 0);
        c.set(Calendar.MILLISECOND, 0);
        return c.getTime();
    }
    if ((m = W3CDTF_FORMAT3.matcher(dateString)).matches()) {
        Calendar c = Calendar.getInstance();
        int year = Integer.parseInt(m.group(1));
        int month = Integer.parseInt(m.group(2)) - 1;
        int date = Integer.parseInt(m.group(3));
        c.set(year, month, date, 0, 0, 0);
        c.set(Calendar.MILLISECOND, 0);
        return c.getTime();
    }
    if ((m = W3CDTF_FORMAT4.matcher(dateString)).matches()) {
        Calendar c = Calendar.getInstance();
        int year = Integer.parseInt(m.group(1));
        int month = Integer.parseInt(m.group(2)) - 1;
        c.set(year, month, 1, 0, 0, 0);
        c.set(Calendar.MILLISECOND, 0);
        return c.getTime();
    }
    if ((m = W3CDTF_FORMAT5.matcher(dateString)).matches()) {
        Calendar c = Calendar.getInstance();
        int year = Integer.parseInt(m.group(1));
        c.set(year, 0, 1, 0, 0, 0);
        c.set(Calendar.MILLISECOND, 0);
        return c.getTime();
    }
    return null;
}

From source file:net.servicefixture.converter.XMLGregorianCalendarConverter.java

private XMLGregorianCalendar calendarToXMLGregorianCalendar(Calendar calendar) {
    XMLGregorianCalendar xmlCal;//from   www.j  ava 2 s .  com
    try {
        xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException("Failed to create XMLGregorianCalendar", e);
    }

    xmlCal.setYear(calendar.get(Calendar.YEAR));
    xmlCal.setMonth(calendar.get(Calendar.MONTH) + 1);
    xmlCal.setDay(calendar.get(Calendar.DAY_OF_MONTH));
    xmlCal.setHour(calendar.get(Calendar.HOUR));
    xmlCal.setMinute(calendar.get(Calendar.MINUTE));
    xmlCal.setSecond(calendar.get(Calendar.SECOND));
    xmlCal.setMillisecond(calendar.get(Calendar.MILLISECOND));
    return xmlCal;
}