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:org.spring.data.gemfire.cache.UserDataStoreCacheLoader.java

protected static Calendar createCalendar(final int year, final int month, final int dayOfMonth,
        final int hourOfDay, final int minute, final int second) {
    Calendar dateTime = Calendar.getInstance();

    dateTime.clear();//from   www  .j a va 2s . c  o  m
    dateTime.set(Calendar.YEAR, year);
    dateTime.set(Calendar.MONTH, month);
    dateTime.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    dateTime.set(Calendar.HOUR_OF_DAY, dayOfMonth);
    dateTime.set(Calendar.MINUTE, minute);
    dateTime.set(Calendar.SECOND, second);

    return dateTime;
}

From source file:py.una.pol.karaku.dao.entity.interceptors.TimeInterceptor.java

@Override
public void intercept(Operation op, Field f, Object bean) {

    Object o = ReflectionUtils.getField(f, bean);

    if (o == null) {
        return;/* w w  w.j  av a 2s.co  m*/
    }

    Time t = f.getAnnotation(Time.class);
    Date date = (Date) o;
    Calendar c = Calendar.getInstance();
    c.setTime(date);

    if ((t == null) || t.type().equals(Time.Type.DATE)) {
        this.handleDate(c);
    } else if (t.type().equals(Time.Type.TIME)) {
        this.handleTime(c);
    }
    // DATETIME no es manejado por que no requeire ningun
    // trato especial

    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    ReflectionUtils.setField(f, bean, c.getTime());
}

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

@BeforeClass
public static void setUp() throws ParseException, GathererException {
    coll = TestHelper.GetTestCollection();
    client = TestHelper.BuildClient();/*  w  ww  . ja  va  2 s  .  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:com.dgpx.web.BaiduTTSBean.java

private void initAccessToken() throws IOException {

    StringBuilder sb = new StringBuilder();
    sb.append("https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials");
    sb.append("&");
    sb.append("client_id=HI1vugSyWg0Gc2GR4RSj2Gwj");
    sb.append("&");
    sb.append("client_secret=ff1aed14438e930fc9a5abb2a14a1714");
    sb.append("&");

    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpGet = new HttpGet(sb.toString());
    CloseableHttpResponse response = httpclient.execute(httpGet);
    int statusCode = response.getStatusLine().getStatusCode();
    if (statusCode == HttpStatus.SC_OK) {
        e = Calendar.getInstance();
        try {//from  w  w  w.j av a 2  s .  c o m
            HttpEntity entity = response.getEntity();
            JSONObject resultJsonObject = null;
            try {
                resultJsonObject = new JSONObject(EntityUtils.toString(entity, "UTF-8"));
                access_token = resultJsonObject.getString("access_token");
                expires_in = Integer.parseInt(resultJsonObject.get("expires_in").toString());
                e.add(Calendar.SECOND, expires_in);
            } catch (IOException | ParseException | JSONException ex) {
                Logger.getLogger(BaiduTTSBean.class.getName()).log(Level.SEVERE, null, ex);
            }
        } finally {
            response.close();
        }
    }

}

From source file:com.intuit.tank.report.JobReportOptions.java

public Date getEndTime() {
    Date ret = null;/*from  ww  w  . j  ava 2  s . co m*/
    if (endDate != null) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(endDate);
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        if (StringUtils.isNotBlank(endTimeString)) {
            try {
                Calendar parsed = Calendar.getInstance();
                parsed.setTime(tf.parse(endTimeString));
                cal.set(Calendar.HOUR_OF_DAY, parsed.get(Calendar.HOUR_OF_DAY));
                cal.set(Calendar.MINUTE, parsed.get(Calendar.MINUTE));
            } catch (ParseException e) {
                LOG.warn("Could not parse time string " + startTimeString);
            }
        }
        ret = cal.getTime();
    }
    return ret;
}

From source file:com.apextom.util.DateUtil.java

/**
 * ????.yyyy-MM-dd// w ww  .ja v  a 2s.c  o m
 *
 * @param date
 * @param formatFormat
 * @return
 */
public static Date getDayDate(String date, String formatFormat) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(strToDate(date, formatFormat));
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    return cal.getTime();
}

From source file:com.greenline.guahao.biz.manager.partners.xm.dataobject.XmResponseDO.java

/**
 * ?/*  w w  w . j ava2s  .  c o m*/
 * @return
 */
public Date countAccessTokenEndTime() {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.SECOND, Integer.valueOf(expires_in));
    accessTokenEndTime = c.getTime();
    return accessTokenEndTime;
}

From source file:eu.annocultor.converters.solr.SolrPeriodsTagger.java

static Date endOfDay(Date date) {
    if (date == null) {
        return null;
    }//ww  w . j ava 2  s.c  o  m
    Calendar calendar = GregorianCalendar.getInstance(TimeZone.getTimeZone("UTC"));
    calendar.setTime(date);
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    return calendar.getTime();
}

From source file:Main.java

/**
 * Parse a date from ISO-8601 formatted string. It expects a format
 * yyyy-MM-ddThh:mm:ss[.sss][Z|[+-]hh:mm]
 *
 * @param date ISO string to parse in the appropriate format.
 * @return the parsed date/*  ww w. j  a v  a2 s . co  m*/
 * @throws IllegalArgumentException if the date is not in the appropriate format
 */
public static Date parse(String date) {
    try {
        int offset = 0;

        // extract year
        int year = parseInt(date, offset, offset += 4);
        checkOffset(date, offset, '-');

        // extract month
        int month = parseInt(date, offset += 1, offset += 2);
        checkOffset(date, offset, '-');

        // extract day
        int day = parseInt(date, offset += 1, offset += 2);
        checkOffset(date, offset, 'T');

        // extract hours, minutes, seconds and milliseconds
        int hour = parseInt(date, offset += 1, offset += 2);
        checkOffset(date, offset, ':');

        int minutes = parseInt(date, offset += 1, offset += 2);
        checkOffset(date, offset, ':');

        int seconds = parseInt(date, offset += 1, offset += 2);
        // milliseconds can be optional in the format
        // always use 0 otherwise returned date will include millis of current time
        int milliseconds = 0;

        if (date.charAt(offset) == '.') {
            checkOffset(date, offset, '.');
            int digitCount = 1;
            while (offset + digitCount < date.length() && digitCount < 3
                    && date.charAt(offset + 1 + digitCount) != 'Z'
                    && date.charAt(offset + 1 + digitCount) != '+'
                    && date.charAt(offset + 1 + digitCount) != '-') {
                digitCount++;
            }
            String msString = date.substring(offset += 1, offset += digitCount);
            while (msString.length() < 3) {
                msString += '0';
            }
            milliseconds = parseInt(msString, 0, 3);
        }

        // extract timezone
        String timezoneId = null;
        while (offset < date.length()) {
            char timezoneIndicator = date.charAt(offset);
            if (timezoneIndicator == '+' || timezoneIndicator == '-') {
                timezoneId = GMT_ID + date.substring(offset);
                break;
            } else if (timezoneIndicator == 'Z') {
                timezoneId = GMT_ID;
                break;
            }
            offset++;
        }
        if (timezoneId == null) {
            throw new IndexOutOfBoundsException("Invalid time zone indicator ");
        }
        TimeZone timezone = TimeZone.getTimeZone(timezoneId);
        if (!timezone.getID().equals(timezoneId)) {
            throw new IndexOutOfBoundsException();
        }

        Calendar calendar = new GregorianCalendar(timezone);
        calendar.setLenient(false);
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DAY_OF_MONTH, day);
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minutes);
        calendar.set(Calendar.SECOND, seconds);
        calendar.set(Calendar.MILLISECOND, milliseconds);

        return calendar.getTime();
    } catch (IndexOutOfBoundsException | IllegalArgumentException e) {
        throw new IllegalArgumentException("Failed to parse date " + date, e);
    }
}

From source file:de.csdev.ebus.command.datatypes.ext.EBusTypeDate.java

@Override
public EBusDateTime decodeInt(byte[] data) throws EBusTypeException {

    if (data == null) {
        // TODO replace value
        return null;
    }//from   w  w  w.  j av  a2s .c  o m

    IEBusType<BigDecimal> bcdType = types.getType(EBusTypeBCD.TYPE_BCD);
    IEBusType<BigDecimal> wordType = types.getType(EBusTypeWord.TYPE_WORD);
    IEBusType<BigDecimal> charType = types.getType(EBusTypeChar.TYPE_CHAR);

    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, 0);

    BigDecimal day = null;
    BigDecimal month = null;
    BigDecimal year = null;

    if (data.length != getTypeLength()) {
        throw new EBusTypeException(
                String.format("Input byte array must have a length of %d bytes!", getTypeLength()));
    }

    if (StringUtils.equals(variant, SHORT)) {
        day = bcdType.decode(new byte[] { data[0] });
        month = bcdType.decode(new byte[] { data[1] });
        year = bcdType.decode(new byte[] { data[2] });

    } else if (StringUtils.equals(variant, DEFAULT)) {
        day = bcdType.decode(new byte[] { data[0] });
        month = bcdType.decode(new byte[] { data[1] });
        year = bcdType.decode(new byte[] { data[3] });

    } else if (StringUtils.equals(variant, HEX_SHORT)) {
        day = charType.decode(new byte[] { data[0] });
        month = charType.decode(new byte[] { data[1] });
        year = charType.decode(new byte[] { data[2] });

    } else if (StringUtils.equals(variant, HEX)) {
        day = charType.decode(new byte[] { data[0] });
        month = charType.decode(new byte[] { data[1] });
        year = charType.decode(new byte[] { data[3] });

    } else if (StringUtils.equals(variant, DAYS)) {
        BigDecimal daysSince1900 = wordType.decode(data);
        calendar.set(1900, 0, 1, 0, 0);
        calendar.add(Calendar.DAY_OF_YEAR, daysSince1900.intValue());
    }

    if (day != null && month != null && year != null) {
        if (day.intValue() < 1 || day.intValue() > 31) {
            throw new EBusTypeException("A valid day must be in a range between 1-31 !");
        }
        if (month.intValue() < 1 || month.intValue() > 12) {
            throw new EBusTypeException("A valid day must be in a range between 1-12 !");
        }
    }

    if (year != null) {
        if (year.intValue() < 70) {
            year = year.add(new BigDecimal(2000));
        } else {
            year = year.add(new BigDecimal(1900));
        }
        calendar.set(Calendar.YEAR, year.intValue());
    }

    if (month != null) {
        calendar.set(Calendar.MONTH, month.intValue() - 1);
    }

    if (day != null && day.intValue() > 0 && day.intValue() < 32) {
        calendar.set(Calendar.DAY_OF_MONTH, day.intValue());
    }

    return new EBusDateTime(calendar, false, true);
}