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:net.sourceforge.eclipsetrader.borsaitalia.HistoryFeed.java

public void updateHistory(Security security, int interval) {
    History history = null;/*from  w w w  .  j a  v a 2s .c om*/
    Calendar from = Calendar.getInstance();
    from.set(Calendar.MILLISECOND, 0);

    if (interval < IHistoryFeed.INTERVAL_DAILY) {
        history = security.getIntradayHistory();
        from.set(Calendar.HOUR_OF_DAY, 0);
        from.set(Calendar.MINUTE, 0);
        from.set(Calendar.SECOND, 0);
        log.info("Updating intraday data for " + security.getCode() + " - " + security.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$
    } else {
        history = security.getHistory();
        if (history.size() == 0)
            from.add(Calendar.YEAR, -CorePlugin.getDefault().getPreferenceStore()
                    .getInt(CorePlugin.PREFS_HISTORICAL_PRICE_RANGE));
        else {
            Bar cd = history.getLast();
            from.setTime(cd.getDate());
            from.add(Calendar.DATE, 1);
        }
        log.info("Updating historical data for " + security.getCode() + " - " + security.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$
    }

    String symbol = null;
    if (security.getHistoryFeed() != null)
        symbol = security.getHistoryFeed().getSymbol();
    if (symbol == null || symbol.length() == 0)
        symbol = security.getCode();

    String code = security.getCode();
    if (code.indexOf('.') != -1)
        code = code.substring(0, code.indexOf('.'));

    try {
        String host = "194.185.192.223"; // "grafici.borsaitalia.it";
        StringBuffer url = new StringBuffer(
                "http://" + host + "/scripts/cligipsw.dll?app=tic_d&action=dwnld4push&cod=" + code + "&codneb=" //$NON-NLS-1$//$NON-NLS-2$
                        + symbol + "&req_type=GRAF_DS&ascii=1&form_id=");
        if (interval < IHistoryFeed.INTERVAL_DAILY)
            url.append("&period=1MIN"); //$NON-NLS-1$
        else {
            url.append("&period=1DAY"); //$NON-NLS-1$
            url.append("&From=" + df.format(from.getTime())); //$NON-NLS-1$
        }
        log.debug(url);

        HttpClient client = new HttpClient();
        client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);

        BundleContext context = BorsaitaliaPlugin.getDefault().getBundle().getBundleContext();
        ServiceReference reference = context.getServiceReference(IProxyService.class.getName());
        if (reference != null) {
            IProxyService proxy = (IProxyService) context.getService(reference);
            IProxyData data = proxy.getProxyDataForHost(host, IProxyData.HTTP_PROXY_TYPE);
            if (data != null) {
                if (data.getHost() != null)
                    client.getHostConfiguration().setProxy(data.getHost(), data.getPort());
                if (data.isRequiresAuthentication())
                    client.getState().setProxyCredentials(AuthScope.ANY,
                            new UsernamePasswordCredentials(data.getUserId(), data.getPassword()));
            }
        }

        HttpMethod method = new GetMethod(url.toString());
        method.setFollowRedirects(true);
        client.executeMethod(method);

        BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));

        // The first line is the header, ignoring
        String inputLine = in.readLine();
        log.trace(inputLine);

        while ((inputLine = in.readLine()) != null) {
            log.trace(inputLine);
            if (inputLine.startsWith("@") == true || inputLine.length() == 0) //$NON-NLS-1$
                continue;
            String[] item = inputLine.split("\\|"); //$NON-NLS-1$

            Bar bar = new Bar();
            bar.setDate(df.parse(item[0]));
            bar.setOpen(Double.parseDouble(item[1]));
            bar.setHigh(Double.parseDouble(item[2]));
            bar.setLow(Double.parseDouble(item[3]));
            bar.setClose(Double.parseDouble(item[4]));
            bar.setVolume((long) Double.parseDouble(item[5]));

            // Remove the old bar, if exists
            int index = history.indexOf(bar.getDate());
            if (index != -1)
                history.remove(index);

            history.add(bar);
        }

        in.close();

    } catch (Exception e) {
        CorePlugin.logException(e);
    }

    CorePlugin.getRepository().save(history);
}

From source file:adalid.commons.util.TimeUtils.java

public static synchronized Date currentDate() {
    calendar.setTimeInMillis(currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return new Date(calendar.getTimeInMillis());
}

From source file:org.psidnell.omnifocus.expr.ExpressionFunctionsTest.java

@Test
public void testDateRoundToDay() throws ParseException {
    Date date1 = ExpressionFunctions.roundToDay(new Date());

    Calendar cal2 = new GregorianCalendar();

    assertNotEquals(date1, cal2.getTime());

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

    assertEquals(date1, cal2.getTime());
}

From source file:DateUtil.java

/**
 * Returns a Date set to the first possible millisecond of the day, just
 * after midnight. If a null day is passed in, a new Date is created.
 * midnight (00m 00h 00s)//from w  w  w . j a  v a  2 s  .  c om
 */
public static Date getStartOfDay(Date day, Calendar cal) {
    if (day == null)
        day = new Date();
    cal.setTime(day);
    cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
    return cal.getTime();
}

From source file:net.kamhon.ieagle.util.DateUtil.java

public static Date formatDateByTime(Date date, int hour, int minute, int second, int milisecond) {
    Calendar calendar = setTime(date);
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, second);
    calendar.set(Calendar.MILLISECOND, milisecond);

    return calendar.getTime();
}

From source file:com.collabnet.ccf.core.utils.DateUtil.java

public static Date convertGMTToTimezoneAbsoluteDate(Date dateValue, String sourceSystemTimezone) {
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone(GMT_TIME_ZONE_STRING));
    cal.setLenient(false);//from  ww w .  j a  v a 2 s  .  c o  m
    cal.setTime(dateValue);
    Calendar newCal = new GregorianCalendar(TimeZone.getTimeZone(sourceSystemTimezone));
    newCal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
    newCal.set(Calendar.MILLISECOND, 0);
    Date returnDate = newCal.getTime();
    return returnDate;
}

From source file:ISO8601DateFormat.java

/**
 * @see java.text.DateFormat#parse(String, ParsePosition)
 *//*from   w w  w.j  a  v  a 2s .co 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;

        calendar.set(year, month, day);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        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:com.sirma.itt.emf.time.ISO8601DateFormat.java

/**
 * Format calendar instance into ISO format.
 * //ww  w  .j ava  2s  . co  m
 * @param calendar
 *            the calendar instance to format
 * @return the ISO formatted string
 */
public static String format(Calendar calendar) {
    if (calendar == null) {
        return null;
    }

    StringBuilder formatted = new StringBuilder(28);
    padInt(formatted, calendar.get(Calendar.YEAR), 4);
    formatted.append('-');
    padInt(formatted, calendar.get(Calendar.MONTH) + 1, 2);
    formatted.append('-');
    padInt(formatted, calendar.get(Calendar.DAY_OF_MONTH), 2);
    formatted.append('T');
    padInt(formatted, calendar.get(Calendar.HOUR_OF_DAY), 2);
    formatted.append(':');
    padInt(formatted, calendar.get(Calendar.MINUTE), 2);
    formatted.append(':');
    padInt(formatted, calendar.get(Calendar.SECOND), 2);
    formatted.append('.');
    padInt(formatted, calendar.get(Calendar.MILLISECOND), 3);

    TimeZone tz = calendar.getTimeZone();
    int offset = tz.getOffset(calendar.getTimeInMillis());
    formatted.append(getTimeZonePadding(offset));

    return formatted.toString();
}

From source file:org.openmrs.module.uiframeworkpatientsummarysupport.fragment.controller.PatientObsFlowsheetFragmentController.java

/**
 * This method was actually added in core as of 1.9
 *///from  w  w  w.  ja va2s. c  o m
private static Date startOfDay(Date date) {
    if (date == null)
        return null;

    Calendar c = Calendar.getInstance();
    c.setTime(date);
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);

    return c.getTime();
}