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:org.wte4j.FormatDateExpressionTest.java

@Test()
public void formateDateTimeLongTest() {

    Calendar calendar = Calendar.getInstance(LOCALE);
    calendar.set(1977, 01, 15, 22, 33, 44);
    calendar.set(Calendar.MILLISECOND, 123);

    testFormat(calendar, "format:dateTime(long, long) value", "15. Februar 1977 22:33:44.123 MEZ");
}

From source file:es.alvsanand.webpage.web.beans.cms.SearchBean.java

public void searchArticlesByDate() throws AlvsanandException {
    logger.info("Launched SearchBean.searchArticlesByDate[date=" + date + "]");

    Calendar calendar = new GregorianCalendar();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 1);

    if (StringUtils.isNotEmpty(date)) {
        String[] tmp = date.split(Globals.DATE_SEPARATOR);

        if (tmp.length > 0) {
            Date beginDate = null;
            Date endDate = null;/* w ww  . j av  a  2  s .c  om*/

            switch (tmp.length) {
            case 1:
                calendar.set(Calendar.YEAR, Integer.parseInt(tmp[0]));
                calendar.set(Calendar.MONTH, 0);
                calendar.set(Calendar.DAY_OF_MONTH, 1);

                beginDate = calendar.getTime();

                calendar.add(Calendar.YEAR, 1);
                endDate = calendar.getTime();

                break;
            case 2:
                calendar.set(Calendar.YEAR, Integer.parseInt(tmp[0]));
                calendar.set(Calendar.MONTH, Integer.parseInt(tmp[1]) - 1);
                calendar.set(Calendar.DAY_OF_MONTH, 1);

                beginDate = calendar.getTime();

                calendar.add(Calendar.MONTH, 1);
                endDate = calendar.getTime();

                break;
            default:
                calendar.set(Calendar.YEAR, Integer.parseInt(tmp[0]));
                calendar.set(Calendar.MONTH, Integer.parseInt(tmp[1]) - 1);
                calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(tmp[2]));

                beginDate = calendar.getTime();

                calendar.add(Calendar.DAY_OF_YEAR, 1);
                endDate = calendar.getTime();

                break;
            }

            articles = getSearchCmsService().getArticlesByDates(beginDate, endDate);
        }

    }
}

From source file:org.oncoblocks.centromere.web.security.BasicTokenUtils.java

/**
 * Creates a {@link TokenDetails} object, based upon submitted {@link UserDetails}.
 * /*  w ww . j a v a 2 s .  c o  m*/
 * @param userDetails
 * @return
 */
public TokenDetails createTokenAndDetails(UserDetails userDetails) {
    String token = this.createToken(userDetails);
    Calendar calendar = Calendar.getInstance();
    Date now = calendar.getTime();
    calendar.add(Calendar.MILLISECOND, this.tokenLifespan.intValue());
    Date expires = calendar.getTime();
    return new TokenDetails(token, userDetails.getUsername(), now, expires);
}

From source file:hubert.team.paragraphs.AdvertsOverviewModel.java

public Calendar getMinDate() {
    final String dateParameter = MgnlContext.getParameter("date");
    if (StringUtils.isNotEmpty(dateParameter)) {
        Date date;//www .jav  a  2s .c  om
        try {
            date = new SimpleDateFormat("yyyy.MM.dd").parse(dateParameter);
        } catch (ParseException e) {
            throw new IllegalArgumentException("Can't parse date " + dateParameter);
        }
        minDate.setTimeInMillis(date.getTime());
    } else {
        String selector = MgnlContext.getAggregationState().getSelector();
        if (StringUtils.isNotEmpty(selector)) {
            manipulateBySelector(minDate, selector);
        }

        this.minDate.set(Calendar.DATE, minDate.getActualMinimum(Calendar.DATE));
        this.minDate.set(Calendar.HOUR_OF_DAY, minDate.getActualMinimum(Calendar.HOUR_OF_DAY));
        this.minDate.set(Calendar.MINUTE, minDate.getActualMinimum(Calendar.MINUTE));
        // If not set the events will be shifted to the previous day on the calendar paragraph if no time has been given eg. dd.MM.yyyy 00.00.0000.
        this.minDate.set(Calendar.SECOND, minDate.getActualMinimum(Calendar.SECOND));
        this.minDate.set(Calendar.MILLISECOND, minDate.getActualMinimum(Calendar.MILLISECOND));
    }
    return minDate;
}

From source file:com.mycompany.CRMFly.serviceLayer.ClientsServiceImpl.java

@Transactional
public Map<Date, Double> getSumsFotDates(Clients client) {
    Long id = client.getId();//  ww w  .  j  ava  2s.co m

    Calendar calendar = new GregorianCalendar();
    Integer monthDifference = 0;
    if (calendar.get(Calendar.MONTH) == Calendar.JANUARY || calendar.get(Calendar.MONTH) == Calendar.APRIL
            || calendar.get(Calendar.MONTH) == Calendar.JULY
            || calendar.get(Calendar.MONTH) == Calendar.OCTOBER) {
        monthDifference = 0;
    } else if (calendar.get(Calendar.MONTH) == Calendar.FEBRUARY || calendar.get(Calendar.MONTH) == Calendar.MAY
            || calendar.get(Calendar.MONTH) == Calendar.AUGUST
            || calendar.get(Calendar.MONTH) == Calendar.NOVEMBER) {
        monthDifference = -1;
    } else if (calendar.get(Calendar.MONTH) == Calendar.MARCH || calendar.get(Calendar.MONTH) == Calendar.JUNE
            || calendar.get(Calendar.MONTH) == Calendar.SEPTEMBER
            || calendar.get(Calendar.MONTH) == Calendar.DECEMBER)
        monthDifference = -2;
    //     Integer dayDifference = -calendar.get(Calendar.DAY_OF_MONTH);
    calendar.add(Calendar.MONTH, monthDifference);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    //      calendar.add(Calendar.DAY_OF_MONTH, dayDifference-1);

    Date beginningOfQuarter = calendar.getTime();
    Double thisQuarterSum = 0.0;
    calendar.add(Calendar.MONTH, -3);
    Date QuarterBackOne = calendar.getTime();
    Double QuarterBackOneSum = 0.0;
    calendar.add(Calendar.MONTH, -3);
    Date QuarterBackTwo = calendar.getTime();
    Double QuarterBackTwoSum = 0.0;
    calendar.add(Calendar.MONTH, -3);
    Date QuarterBackThree = calendar.getTime();
    Double QuarterBackThreeSum = 0.0;

    List<Contracts> contracts = clientsDAO.getContractsForClient(id);
    HashMap<Date, Double> sums = new HashMap<Date, Double>();
    for (Contracts contract : contracts) {
        Date date = contract.getBegin_date();
        if (date.after(beginningOfQuarter))
            thisQuarterSum += contract.getTotalSum();
        else if (date.after(QuarterBackOne))
            QuarterBackOneSum += contract.getTotalSum();
        else if (date.after(QuarterBackTwo))
            QuarterBackTwoSum += contract.getTotalSum();
        else if (date.after(QuarterBackThree))
            QuarterBackThreeSum += contract.getTotalSum();
    }
    sums.put(beginningOfQuarter, thisQuarterSum);
    sums.put(QuarterBackOne, QuarterBackOneSum);
    sums.put(QuarterBackTwo, QuarterBackTwoSum);
    sums.put(QuarterBackThree, QuarterBackThreeSum);
    return sums;
}

From source file:com.frey.repo.DateUtil.java

/**
 * ???/*from  w ww  .j  a  v a2 s.c  om*/
 *
 * @return Date
 */
public static Date curDate5() throws ParseException {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:com.livinglogic.ul4.FunctionFormat.java

public static String call(Date obj, String formatString, Locale locale) {
    if (locale == null)
        locale = Locale.ENGLISH;//  w ww.  ja  v  a  2 s.c  om
    Calendar calendar = new GregorianCalendar();
    calendar.setTime((Date) obj);
    StringBuilder buffer = new StringBuilder();
    boolean escapeCharacterFound = false;
    int formatStringLength = formatString.length();
    for (int i = 0; i < formatStringLength; i++) {
        char c = formatString.charAt(i);
        if (escapeCharacterFound) {
            switch (c) {
            case 'a':
                buffer.append(new SimpleDateFormat("EE", locale).format(obj));
                break;
            case 'A':
                buffer.append(new SimpleDateFormat("EEEE", locale).format(obj));
                break;
            case 'b':
                buffer.append(new SimpleDateFormat("MMM", locale).format(obj));
                break;
            case 'B':
                buffer.append(new SimpleDateFormat("MMMM", locale).format(obj));
                break;
            case 'c': {
                String format = cFormats.get(locale.getLanguage());
                if (format == null)
                    format = cFormats.get("en");
                buffer.append(call(obj, format, locale));
                break;
            }
            case 'd':
                buffer.append(twodigits.format(calendar.get(Calendar.DAY_OF_MONTH)));
                break;
            case 'f':
                buffer.append(sixdigits.format(calendar.get(Calendar.MILLISECOND) * 1000));
                break;
            case 'H':
                buffer.append(twodigits.format(calendar.get(Calendar.HOUR_OF_DAY)));
                break;
            case 'I':
                buffer.append(twodigits.format(((calendar.get(Calendar.HOUR_OF_DAY) - 1) % 12) + 1));
                break;
            case 'j':
                buffer.append(threedigits.format(calendar.get(Calendar.DAY_OF_YEAR)));
                break;
            case 'm':
                buffer.append(twodigits.format(calendar.get(Calendar.MONTH) + 1));
                break;
            case 'M':
                buffer.append(twodigits.format(calendar.get(Calendar.MINUTE)));
                break;
            case 'p':
                buffer.append(new SimpleDateFormat("aa", locale).format(obj));
                break;
            case 'S':
                buffer.append(twodigits.format(calendar.get(Calendar.SECOND)));
                break;
            case 'U':
                buffer.append(twodigits.format(BoundDateMethodWeek.call(obj, 6)));
                break;
            case 'w':
                buffer.append(weekdayFormats.get(calendar.get(Calendar.DAY_OF_WEEK)));
                break;
            case 'W':
                buffer.append(twodigits.format(BoundDateMethodWeek.call(obj, 0)));
                break;
            case 'x': {
                String format = xFormats.get(locale.getLanguage());
                if (format == null)
                    format = xFormats.get("en");
                buffer.append(call(obj, format, locale));
                break;
            }
            case 'X': {
                String format = XFormats.get(locale.getLanguage());
                if (format == null)
                    format = XFormats.get("en");
                buffer.append(call(obj, format, locale));
                break;
            }
            case 'y':
                buffer.append(twodigits.format(calendar.get(Calendar.YEAR) % 100));
                break;
            case 'Y':
                buffer.append(fourdigits.format(calendar.get(Calendar.YEAR)));
                break;
            default:
                buffer.append(c);
                break;
            }
            escapeCharacterFound = false;
        } else {
            if (c == '%')
                escapeCharacterFound = true;
            else
                buffer.append(c);

        }
    }
    if (escapeCharacterFound)
        buffer.append('%');
    return buffer.toString();
}

From source file:gemlite.core.common.DateUtil.java

/**
 * /*from w  w  w.  j ava2 s .c o m*/
 * @return
 */
public static long today() {
    Calendar c = Calendar.getInstance();
    c.setTime(new Date());
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.HOUR_OF_DAY, 0);
    return c.getTimeInMillis();
}

From source file:at.ac.uniklu.mobile.sportal.api.UnikluSportalApiClient.java

public List<Termin> getTermineHeute(Integer[] lvkeys) throws ApiClientException, ApiServerException {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    Date todayBegin = calendar.getTime();
    calendar.add(Calendar.DAY_OF_YEAR, 1);
    Date todayEnd = calendar.getTime();
    return getTermine(todayBegin, todayEnd, null, lvkeys);
}

From source file:net.sourceforge.eclipsetrader.yahoo.HistoryFeed.java

public void updateHistory(Security security, int interval) {
    if (interval == IHistoryFeed.INTERVAL_DAILY) {
        Calendar from = Calendar.getInstance();
        Calendar to = Calendar.getInstance();

        History history = security.getHistory();
        if (history.size() == 0)
            from.add(Calendar.YEAR, -CorePlugin.getDefault().getPreferenceStore()
                    .getInt(CorePlugin.PREFS_HISTORICAL_PRICE_RANGE));
        else {//www.j  a  v  a 2  s  .c o  m
            Bar cd = history.getLast();
            if (cd != null) {
                from.setTime(cd.getDate());
                from.add(Calendar.DATE, 1);
            }
        }

        try {
            HttpClient client = new HttpClient();
            client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
            String host = "ichart.finance.yahoo.com"; //$NON-NLS-1$
            BundleContext context = YahooPlugin.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()));
                }
            }

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

            // If the last bar from the data is from a date before today, then
            // download the historical data, otherwise it's enough to download the data for today.
            to.add(Calendar.DAY_OF_MONTH, -1);
            to.set(Calendar.HOUR, 0);
            to.set(Calendar.MINUTE, 0);
            to.set(Calendar.SECOND, 0);
            to.set(Calendar.MILLISECOND, 0);
            Bar lastHistoryBar = history.getLast();
            Date lastDate;
            if (lastHistoryBar == null)
                lastDate = from.getTime();
            else
                lastDate = lastHistoryBar.getDate();
            if (lastDate.before(to.getTime())) {
                log.info("Updating historical data for " + security.getCode() + " - " //$NON-NLS-1$//$NON-NLS-2$
                        + security.getDescription());

                StringBuffer url = new StringBuffer("http://" + host + "/table.csv" + "?s="); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                url.append(symbol);
                url.append("&d=" + to.get(Calendar.MONTH) + "&e=" + to.get(Calendar.DAY_OF_MONTH) + "&f=" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                        + to.get(Calendar.YEAR));
                url.append("&g=d"); //$NON-NLS-1$
                url.append("&a=" + from.get(Calendar.MONTH) + "&b=" + from.get(Calendar.DAY_OF_MONTH) + "&c=" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                        + from.get(Calendar.YEAR));
                url.append("&ignore=.csv"); //$NON-NLS-1$
                log.debug(url);

                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("<")) //$NON-NLS-1$
                        continue;
                    String[] item = inputLine.split(","); //$NON-NLS-1$
                    if (item.length < 6)
                        continue;

                    Calendar day = Calendar.getInstance();
                    try {
                        day.setTime(df.parse(item[0]));
                    } catch (Exception e) {
                        try {
                            day.setTime(dfAlt.parse(item[0]));
                        } catch (Exception e1) {
                            log.error(e1, e1);
                        }
                    }
                    day.set(Calendar.HOUR, 0);
                    day.set(Calendar.MINUTE, 0);
                    day.set(Calendar.SECOND, 0);
                    day.set(Calendar.MILLISECOND, 0);

                    Bar bar = new Bar();
                    bar.setDate(day.getTime());
                    bar.setOpen(Double.parseDouble(item[1].replace(',', '.')));
                    bar.setHigh(Double.parseDouble(item[2].replace(',', '.')));
                    bar.setLow(Double.parseDouble(item[3].replace(',', '.')));
                    bar.setClose(Double.parseDouble(item[4].replace(',', '.')));
                    bar.setVolume(Long.parseLong(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();
            }

            // Get the data for today (to-date) using a different URL at Yahoo!
            //Bar lastbar = history.getLast
            log.debug("Get data for today using a separate URL..."); //$NON-NLS-1$
            StringBuffer url = new StringBuffer(
                    "http://finance.yahoo.com/d/quotes.csv?s=" + symbol + "&f=sl1d1t1c1ohgv&e=.csv"); //$NON-NLS-1$ //$NON-NLS-2$
            log.debug(url);

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

            BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
            String inputLine = in.readLine();
            log.trace(inputLine);
            String[] item = inputLine.split(","); //$NON-NLS-1$
            item[2] = item[2].replace("\"", ""); //$NON-NLS-1$ //$NON-NLS-2$

            SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy", Locale.US); //$NON-NLS-1$
            Calendar day = Calendar.getInstance();

            // Transfer the data from the string array to the Bar
            day.setTime(df.parse(item[2]));
            Bar bar = new Bar();
            bar.setDate(day.getTime());
            bar.setOpen(Double.parseDouble(item[5]));
            bar.setClose(Double.parseDouble(item[1]));
            bar.setHigh(Double.parseDouble(item[6]));
            bar.setLow(Double.parseDouble(item[7]));
            bar.setVolume(Long.parseLong(item[8]));

            // 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) {
            log.error(e, e);
        }

        CorePlugin.getRepository().save(history);
    } else
        log.warn("Intraday data not supported for " + security.getCode() + " - " + security.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$
}