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:net.sf.l2j.gameserver.model.entity.ClanHallSiege.java

public void setNewSiegeDate(long siegeDate, int ClanHallId, int hour) {
    Calendar tmpDate = Calendar.getInstance();
    if (siegeDate <= System.currentTimeMillis()) {
        tmpDate.setTimeInMillis(System.currentTimeMillis());
        tmpDate.add(Calendar.DAY_OF_MONTH, 3);
        tmpDate.set(Calendar.DAY_OF_WEEK, 6);
        tmpDate.set(Calendar.HOUR_OF_DAY, hour);
        tmpDate.set(Calendar.MINUTE, 0);
        tmpDate.set(Calendar.SECOND, 0);
        setSiegeDate(tmpDate);/*from ww  w.jav  a 2  s  . co m*/
        Connection con = null;
        try {
            con = L2DatabaseFactory.getInstance().getConnection();
            PreparedStatement statement = con
                    .prepareStatement("UPDATE clanhall_siege SET siege_data=? WHERE id = ?");
            statement.setLong(1, getSiegeDate().getTimeInMillis());
            statement.setInt(2, ClanHallId);
            statement.execute();
            statement.close();
        } catch (Exception e) {
            _log.error("Exception: can't save clanhall siege date: " + e.getMessage(), e);
        } finally {
            try {
                if (con != null)
                    con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.ar.dev.tierra.api.service.FacturaService.java

public Page getReservasDay(Integer page, Integer size, int idSucursal) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    Date from = calendar.getTime();
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    Date to = calendar.getTime();
    Page paged = facturaRepository.findReservasByDate(from, to, new PageRequest(page, size), idSucursal);
    return paged;
}

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

private XMLGregorianCalendar calendarToXMLGregorianCalendar(Calendar calendar) {
    XMLGregorianCalendar xmlCal;//from   w w w .  j  a va 2  s. c o m
    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;
}

From source file:com.silverpeas.calendar.DateTime.java

/**
 * Creates a new date time from the specified parts of the time specification year month day hour
 * minute second millisecond. The hour, minute, second and millisecond parts are optional; if not
 * passed, they are set at 0. For example, the following patterns are valid:
 * <ul>/*from   w  w  w  .  ja v  a2s  .co m*/
 * <li>at(2011, 5, 23, 10, 57, 23, 12) meaning in ISO 86601 2011-05-23T10:57:23.012</li>
 * <li>at(2011, 5, 23, 10, 57, 23) meaning in ISO 86601 2011-05-23T10:57:23.00</li>
 * <li>at(2011, 5, 23, 10, 57) meaning in ISO 86601 2011-05-23T10:57:00.00</li>
 * <li>at(2011, 5, 23, 10) meaning in ISO 86601 2011-05-23T10:00:00.00</li>
 * <li>at(2011, 5, 23) meaning in ISO 86601 2011-05-23T00:00:00.00</li>
 * </ul>
 * @param timeParts the different parts of the date time to set in the following order: year,
 * month, day, hour, minute, second, millisecond. The year, month, and day are mandatory whereas
 * other time parts are optional. If one optional part isn't passed, then it is set to 0.
 * @return a date time matching the specified date and time specification.
 */
public static DateTime dateTimeAt(int... timeParts) {
    if (timeParts.length < 3) {
        throw new IllegalArgumentException("The year, month and day must be set");
    }
    Calendar calendar = Calendar.getInstance();
    calendar.set(timeParts[0], timeParts[1], timeParts[2], 0, 0, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    if (timeParts.length >= 4) {
        calendar.set(Calendar.HOUR_OF_DAY, timeParts[3]);
        if (timeParts.length >= 5) {
            calendar.set(Calendar.MINUTE, timeParts[4]);
            if (timeParts.length >= 6) {
                calendar.set(Calendar.SECOND, timeParts[5]);
                if (timeParts.length >= 7) {
                    calendar.set(Calendar.MILLISECOND, timeParts[6]);
                }
            }
        }
    }
    return new DateTime(calendar.getTime());
}

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

/**
 * ?(dataRetentionPeriod)????00:00:00?epoch()??
 * @param dataRetentionPeriod/*from   w  w  w . jav a 2 s  .  c  o  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:ch.cyberduck.core.b2.B2AuthorizedUrlProvider.java

@Override
public DescriptiveUrl toDownloadUrl(final Path file, final Void none, final PasswordCallback callback)
        throws BackgroundException {
    if (file.isVolume()) {
        return DescriptiveUrl.EMPTY;
    }/*w w  w .ja  va  2  s  . co m*/
    if (file.isFile()) {
        final String download = String.format("%s/file/%s/%s", session.getClient().getDownloadUrl(),
                URIEncoder.encode(containerService.getContainer(file).getName()),
                URIEncoder.encode(containerService.getKey(file)));
        try {
            final int seconds = 604800;
            // Determine expiry time for URL
            final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            expiry.add(Calendar.SECOND, seconds);
            final String token = session.getClient()
                    .getDownloadAuthorization(new B2FileidProvider(session)
                            .getFileid(containerService.getContainer(file), new DisabledListProgressListener()),
                            StringUtils.EMPTY, seconds);
            return new DescriptiveUrl(URI.create(String.format("%s?Authorization=%s", download, token)),
                    DescriptiveUrl.Type.signed,
                    MessageFormat.format(LocaleFactory.localizedString("{0} URL"),
                            LocaleFactory.localizedString("Pre-Signed", "S3")) + " ("
                            + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")",
                                    UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())));
        } catch (B2ApiException e) {
            throw new B2ExceptionMappingService().map(e);
        } catch (IOException e) {
            throw new DefaultIOExceptionMappingService().map(e);
        }
    }
    return DescriptiveUrl.EMPTY;
}

From source file:com.sammyun.controller.console.StaticController.java

/**
 * ???//  w ww.  jav a2s.  com
 */
@RequestMapping(value = "/build", method = RequestMethod.POST)
public @ResponseBody Map<String, Object> build(BuildType buildType, Long articleCategoryId,
        Long productCategoryId, Date beginDate, Date endDate, Integer first, Integer count, String lang,
        HttpServletRequest request, HttpServletResponse response) {
    long startTime = System.currentTimeMillis();
    if (beginDate != null) {
        Calendar calendar = DateUtils.toCalendar(beginDate);
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND));
        beginDate = calendar.getTime();
    }
    if (endDate != null) {
        Calendar calendar = DateUtils.toCalendar(endDate);
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
        endDate = calendar.getTime();
    }
    if (first == null || first < 0) {
        first = 0;
    }
    if (count == null || count <= 0) {
        count = 50;
    }
    int buildCount = 0;
    boolean isCompleted = true;
    if (lang == null) {
        lang = "zh_CN";
    }
    staticService.setLocale(lang);
    WebUtils.removeCookie(request, response, langCookieName);
    WebUtils.addCookie(request, response, langCookieName, lang);
    if (buildType == BuildType.index) {
        buildCount = staticService.buildIndex();
    } else if (buildType == BuildType.article) {
    } else if (buildType == BuildType.other) {
        buildCount = staticService.buildOther();
    }
    long endTime = System.currentTimeMillis();
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("first", first);
    map.put("buildCount", buildCount);
    map.put("buildTime", endTime - startTime);
    map.put("isCompleted", isCompleted);
    return map;
}

From source file:at.florian_lentsch.expirysync.NotifyChecker.java

private static long getFirstStartMillis(Context appContext) {
    final SharedPreferences sharedPref = appContext.getSharedPreferences("main", Context.MODE_PRIVATE);
    long firstStartMillis = sharedPref.getLong(SettingsActivity.KEY_ALERT_TIME, -1);
    if (firstStartMillis == -1) {
        return -1;
    }/*from  w w w .j  av a2  s.  c  o m*/

    Calendar midnight = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    midnight.set(Calendar.HOUR_OF_DAY, 0);
    midnight.set(Calendar.MINUTE, 0);
    midnight.set(Calendar.SECOND, 0);
    midnight.set(Calendar.MILLISECOND, 0);

    // add "today at 0:00" to the ms value for the alarm (else the alarm
    // would be scheduled for 1970-01-01):
    firstStartMillis += midnight.getTimeInMillis();

    // if we're already past the alarm time today, we need to add another
    // day:
    if (firstStartMillis <= Calendar.getInstance().getTimeInMillis()) {
        firstStartMillis += AlarmManager.INTERVAL_DAY;
    }

    return firstStartMillis;
}

From source file:com.lohika.alp.reporter.fe.dao.TestMethodDAOImpl.java

private DetachedCriteria getFilteredCriteria(TestMethodFilter filter) {
    DetachedCriteria criteria = DetachedCriteria.forClass(TestMethod.class);

    criteria.createAlias("testInstance", "testInstance").createAlias("testInstance.testClass", "testClass")
            .createAlias("testInstance.test", "test");

    if (filter.getFrom() != null && filter.getTill() != null) {
        Calendar c = Calendar.getInstance();

        c.setTime(filter.getFrom());//w  w  w .  j  av a2 s . co  m
        c.set(Calendar.HOUR_OF_DAY, c.getActualMinimum(Calendar.HOUR_OF_DAY));
        c.set(Calendar.MINUTE, c.getActualMinimum(Calendar.MINUTE));
        c.set(Calendar.SECOND, c.getActualMinimum(Calendar.SECOND));
        c.set(Calendar.MILLISECOND, c.getActualMinimum(Calendar.MILLISECOND));
        Date from = c.getTime();

        c.setTime(filter.getTill());
        c.set(Calendar.HOUR_OF_DAY, c.getActualMaximum(Calendar.HOUR_OF_DAY));
        c.set(Calendar.MINUTE, c.getActualMaximum(Calendar.MINUTE));
        c.set(Calendar.SECOND, c.getActualMaximum(Calendar.SECOND));
        c.set(Calendar.MILLISECOND, c.getActualMaximum(Calendar.MILLISECOND));
        Date till = c.getTime();

        criteria.add(Restrictions.between("startDate", from.getTime(), till.getTime()));
    }

    if (filter.getCl() != "" && filter.getCl() != null) {
        try {
            criteria.add(querytr.translate("testClass.name", filter.getCl()));
        } catch (QueryTranslatorException e) {
            // TODO Put QueryTranslatorException into log
            e.printStackTrace();
        }
    }

    if (filter.getGr() != "" && filter.getGr() != null) {
        criteria.createAlias("groups", "groups");

        try {
            criteria.add(querytr.translate("groups.name", filter.getGr()));
        } catch (QueryTranslatorException e) {
            // TODO Put QueryTranslatorException into log
            e.printStackTrace();
        }
    }

    return criteria;
}