Example usage for java.util Calendar SECOND

List of usage examples for java.util Calendar SECOND

Introduction

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

Prototype

int SECOND

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

Click Source Link

Document

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

Usage

From source file:Main.java

private static String doFormatDate(Calendar calendar) {
    return String.format(Locale.ROOT, "%04d-%02d-%02dT%02d:%02d:%02dZ", calendar.get(Calendar.YEAR),
            calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH),
            calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND));
}

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

public void updateHistory(Security security, int interval) {
    History history = null;//  w  w w.  ja  v  a2  s .  c  o m
    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:com.ar.dev.tierra.api.dao.impl.NotaCreditoDAOImpl.java

@Override
public List<NotaCredito> getDaily() {
    Criteria criteria = getSession().createCriteria(NotaCredito.class);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    Date fromDate = calendar.getTime();
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    Date toDate = calendar.getTime();
    criteria.add(Restrictions.between("fechaCreacion", fromDate, toDate));
    criteria.addOrder(Order.desc("idNotaCredito"));
    List<NotaCredito> list = criteria.list();
    return list;/*ww  w.j  a  va 2 s.  co m*/
}

From source file:org.openehealth.coala.converter.PXSDateConverterTest.java

/**
 * @throws java.lang.Exception// w  ww  .ja v  a 2 s.  c  o  m
 */
@Before
public void setUp() throws Exception {
    ResourceBundle properties = ResourceBundle.getBundle("coala-document");
    longPattern = properties.getString("coala.consent.longdatepattern");
    shortPattern = properties.getString("coala.consent.shortdatepattern");

    GregorianCalendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, 2011);
    cal.set(Calendar.MONTH, Calendar.JANUARY);
    cal.set(Calendar.DAY_OF_MONTH, 15);
    cal.set(Calendar.HOUR, 3);
    cal.set(Calendar.MINUTE, 36);
    cal.set(Calendar.SECOND, 50);
    cal.set(Calendar.MILLISECOND, 0);
    referenceDateLong = cal.getTime();

    cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, 2011);
    cal.set(Calendar.MONTH, Calendar.JANUARY);
    cal.set(Calendar.DAY_OF_MONTH, 15);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    referenceDateShort = cal.getTime();

}

From source file:com.aimdek.ccm.dao.impl.test.CreditCardDaoImplTest.java

/**
 * initialize.//from w w  w .  ja v a2 s  . c  o  m
 */
@Before
public void initialize() {

    List<CreditCard> creditcardList = new ArrayList<CreditCard>();

    CreditCard creditCard = new CreditCard();
    creditCard.setAvailableCreditLimit(15000);
    creditCard.setCardNumber("1234-1234-1234-0008");
    creditCard.setCreditLimit(20000);
    creditCard.setCvv(420);
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    creditCard.setLastStatementDate(calendar.getTime());
    creditCard.setStatementDate(new Date());
    creditCard.setNameOnCard("Test1 Test1");
    creditCard.setCardHolderId(1);
    creditCard.setValidFromDate(new Date());
    creditCard.setValidToDate(new Date());
    creditCardRepository.saveCreditCard(creditCard);
    creditCardId = creditCard.getId();

    CreditCard creditCard1 = new CreditCard();
    creditCard1.setAvailableCreditLimit(15000);
    creditCard1.setCardNumber("2345-1234-2345-0009");
    creditCard1.setCreditLimit(20000);
    creditCard1.setCvv(420);
    creditCard1.setLastStatementDate(calendar.getTime());
    creditCard1.setStatementDate(new Date());
    creditCard1.setNameOnCard("Test2 Test2");
    creditCard1.setCardHolderId(2);
    creditCard1.setValidFromDate(new Date());
    creditCard1.setValidToDate(new Date());
    creditcardList.add(creditCard1);

    CreditCard creditCard2 = new CreditCard();
    creditCard2.setAvailableCreditLimit(15000);
    creditCard2.setCardNumber("1234-1234-1234-0010");
    creditCard2.setCreditLimit(20000);
    creditCard2.setCvv(420);
    creditCard2.setLastStatementDate(calendar.getTime());
    creditCard2.setStatementDate(new Date());
    creditCard2.setNameOnCard("Test3 Test3");
    creditCard2.setCardHolderId(3);
    creditCard2.setValidFromDate(new Date());
    creditCard2.setValidToDate(new Date());
    creditcardList.add(creditCard2);

    CreditCard creditCard3 = new CreditCard();
    creditCard3.setAvailableCreditLimit(15000);
    creditCard3.setCardNumber("2345-1234-2345-0011");
    creditCard3.setCreditLimit(20000);
    creditCard3.setCvv(420);
    creditCard3.setLastStatementDate(calendar.getTime());
    creditCard3.setStatementDate(new Date());
    creditCard3.setNameOnCard("Test4 Test4");
    creditCard3.setCardHolderId(4);
    creditCard3.setValidFromDate(new Date());
    creditCard3.setValidToDate(new Date());
    creditcardList.add(creditCard3);

    CreditCard creditCard5 = new CreditCard();
    creditCard5.setAvailableCreditLimit(15000);
    creditCard5.setCardNumber("1234-1234-1234-0012");
    creditCard5.setCreditLimit(20000);
    creditCard5.setCvv(420);
    creditCard5.setLastStatementDate(calendar.getTime());
    creditCard5.setStatementDate(new Date());
    creditCard5.setNameOnCard("Test3 Test3");
    creditCard5.setCardHolderId(4);
    creditCard5.setValidFromDate(new Date());
    creditCard5.setValidToDate(new Date());
    creditcardList.add(creditCard5);

    creditCardRepository.save(creditcardList);
}

From source file:erpsystem.chart.Charts.java

private static Calendar copyCalendar(Calendar calendar) {
    Calendar result = Calendar.getInstance();
    result.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH),
            calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND));
    return result;
}

From source file:org.openmrs.module.pharmacyapi.api.prescription.util.NewPrescriptionItemGenerator.java

private Date getExpirationDateMinus2Days(final PrescriptionItem item) {

    final Calendar calendar = Calendar.getInstance();
    calendar.setTime(item.getDrugOrder().getEncounter().getDateCreated());
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.add(Calendar.DAY_OF_MONTH, 10);

    while ((calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
            || (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)) {

        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }//from   ww  w  .ja  va  2  s .  c  o m

    return calendar.getTime();
}

From source file:net.sourceforge.eclipsetrader.trading.DataCollector.java

public void update(Observable o, Object arg) {
    Security security = (Security) arg;
    Quote quote = security.getQuote();//  w  ww.ja v a  2s.com

    if (!security.isEnableDataCollector() || quote == null || quote.getDate() == null)
        return;

    barTime.setTime(quote.getDate());
    barTime.set(Calendar.SECOND, 0);
    barTime.set(Calendar.MILLISECOND, 0);

    int quoteTime = barTime.get(Calendar.HOUR_OF_DAY) * 60 + barTime.get(Calendar.MINUTE);
    if (quoteTime < security.getBeginTime() || quoteTime > security.getEndTime())
        return;

    MapData data = (MapData) map.get(security);
    if (data.bar != null && data.bar.getDate() != null) {
        if (barTime.after(data.nextBarTime) || barTime.equals(data.nextBarTime)) {
            data.history.add(data.bar);

            if (security.getKeepDays() != 0) {
                Calendar keepLimit = Calendar.getInstance();
                keepLimit.setTime(data.bar.getDate());
                keepLimit.set(Calendar.HOUR, 0);
                keepLimit.set(Calendar.MINUTE, 0);
                keepLimit.set(Calendar.SECOND, 0);
                keepLimit.set(Calendar.MILLISECOND, 0);
                keepLimit.add(Calendar.DATE, -security.getKeepDays());

                Date limit = keepLimit.getTime();
                while (data.history.size() > 0 && ((Bar) data.history.get(0)).getDate().before(limit))
                    data.history.remove(0);
            }

            try {
                log.trace("Notifying intraday data updated for " + security.getCode() + " - "
                        + security.getDescription());
                data.history.notifyObservers();
                data.changes++;
                if (data.changes >= changes) {
                    CorePlugin.getRepository().save(data.history);
                    data.changes = 0;
                }
            } catch (Exception e) {
                log.error(e, e);
            }
            data.bar = null;
        }
    } else if (data.bar == null) {
        data.bar = new Bar();
        data.bar.setOpen(quote.getLast());
        data.bar.setHigh(quote.getLast());
        data.bar.setLow(quote.getLast());
        data.bar.setClose(quote.getLast());
        data.volume = quote.getVolume();
        barTime.add(Calendar.MINUTE, -(barTime.get(Calendar.MINUTE) % minutes));
        data.bar.setDate(barTime.getTime());
        data.nextBarTime.setTime(data.bar.getDate());
        data.nextBarTime.add(Calendar.MINUTE, minutes);
    }

    if (data.bar != null) {
        if (quote.getLast() > data.bar.getHigh())
            data.bar.setHigh(quote.getLast());
        if (quote.getLast() < data.bar.getLow())
            data.bar.setLow(quote.getLast());
        data.bar.setClose(quote.getLast());
        data.bar.setVolume(quote.getVolume() - data.volume);
    }
}

From source file:fr.syncarnet.tasks.Task.java

/** 
 * Builds a task object giving it a unique UUID and storing the current time as entry date.
 * @param description//from  w  w  w.  j a v  a2s . c  o  m
 *    The description of the task
 * @param due
 *    Set it to <b>null</b> if not used
 * @param project
 *    Set it to <b>null</b> if not used
 * @param priority
 *    Set it to <b>MEDIUM</b> if not used
 */
public Task(String description, Calendar due, String project, Priority priority) {
    this.entry = new Date().getTime();
    this.uuid = UUID.randomUUID();
    this.description = description;
    if (due != null) {
        due.set(Calendar.HOUR_OF_DAY, 0);
        due.set(Calendar.MINUTE, 0);
        due.set(Calendar.SECOND, 0);
        due.set(Calendar.MILLISECOND, 0);
    }
    this.due = due;
    if (project != null && !project.equals("")) {
        this.project = project;
    }
    this.priority = priority;
}

From source file:churashima.action.manage.ExpensesAction.java

@Execute(validator = false)
public String index() {

    Date date = new Date();
    if (StringUtils.isEmpty(expensesForm.strDate)) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        expensesForm.strDate = sdf.format(date);
    }//from  w  w  w .ja v a 2  s.c  o  m

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

    ExpensesDao expensesDao = SingletonS2Container.getComponent(ExpensesDao.class);
    List<Expenses> expensesList = expensesDao.selectForSearch(null, null, null, null, null, null, null, null,
            new Timestamp(cal.getTimeInMillis()));

    expensesForm.expensesList = expensesList;

    //       expensesForm.subjectId = null;
    expensesForm.place = null;
    expensesForm.name = null;
    expensesForm.price = BigDecimal.valueOf(0);
    expensesForm.comment = null;
    expensesForm.isExcludeTax = null;

    SubjectDao subjectDao = SingletonS2Container.getComponent(SubjectDao.class);
    expensesForm.subjectList = subjectDao.selectForSearch(null, Const.STATUS_STARTING);

    return "expenses.jsp";
}