Example usage for java.util GregorianCalendar getTime

List of usage examples for java.util GregorianCalendar getTime

Introduction

In this page you can find the example usage for java.util GregorianCalendar getTime.

Prototype

public final Date getTime() 

Source Link

Document

Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch").

Usage

From source file:org.apache.torque.generated.peer.DateTest.java

/**
 * Checks that a select does not match when a timestamp to select
 * is a millisecond away from the timestamp saved in the database.
 *
 * @throws TorqueException if a problem occurs.
 *///from  ww  w.  j av a  2s. c o  m
public void testSelectWithMillisecondsOnTimestampMillisecondMismatch() throws TorqueException {
    if (!timestampHasMillisecondAccuracy()) {
        return;
    }
    cleanDateTimeTimestampTable();

    // insert new DateTest object to db
    DateTimeTimestampType dateTimeTimestamp = new DateTimeTimestampType();
    dateTimeTimestamp.setDateValue(new Date());
    dateTimeTimestamp.setTimeValue(new Date());
    GregorianCalendar calendar = new GregorianCalendar(2010, 1, 23);
    calendar.set(GregorianCalendar.MILLISECOND, 123);
    dateTimeTimestamp.setTimestampValue(calendar.getTime());
    dateTimeTimestamp.save();

    // execute matching select
    Criteria criteria = new Criteria();
    calendar = new GregorianCalendar(2010, 1, 23);
    calendar.set(GregorianCalendar.MILLISECOND, 124);
    criteria.where(DateTimeTimestampTypePeer.TIMESTAMP_VALUE, calendar.getTime());
    List<DateTimeTimestampType> result = DateTimeTimestampTypePeer.doSelect(criteria);

    // verify
    assertEquals(0, result.size());
}

From source file:org.eurekastreams.server.persistence.TabGroupMapper.java

/**
 * Clean up deleted tabs here using the expired date set earlier. Currently
 * this is hard-coded to be at least 20 (configurable) minutes since the tab
 * was originally deleted, but could be much longer because it is dependent
 * on the next tab that is deleted. If one tab is deleted on Jan 1st and the
 * next tab is deleted on March 1st, the 1st tab will remain flagged as
 * deleted in the database until March 1st so we definitely need a full
 * timestamp for this object./*from  ww w . jav  a2s  . c  o m*/
 */
private void cleanUpDeletedTabs() {
    GregorianCalendar expiredDateTime = new GregorianCalendar();
    expiredDateTime.add(Calendar.MINUTE, -undeleteTabWindowInMinutes);

    getEntityManager()
            .createQuery(
                    "delete from Gadget gd where gd.deleted = true " + "and gd.dateDeleted < :expiredTimestamp")
            .setParameter("expiredTimestamp", expiredDateTime.getTime()).executeUpdate();

    getEntityManager()
            .createQuery(
                    "delete from Tab de where de.deleted = true " + "and de.dateDeleted < :expiredTimestamp")
            .setParameter("expiredTimestamp", expiredDateTime.getTime()).executeUpdate();

    try {
        getEntityManager()
                .createQuery("delete from TabTemplate de where de.deleted = true "
                        + "and de.dateDeleted < :expiredTimestamp")
                .setParameter("expiredTimestamp", expiredDateTime.getTime()).executeUpdate();
    } catch (Exception e) {
        // This should never happen because a tab template is not marked as deleted unless
        // there are no reference to it by active tabs
        logger.debug("Unable to delete a tab template because there is still a tab that references it");
    }

}

From source file:com.esd.ps.LoginController.java

/**
 * ,//  w ww  .  j  a  v a 2 s . c o m
 * @return
 */
@RequestMapping(value = "/moneyList", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> moneyListPost() {
    Map<String, Object> map = new HashMap<String, Object>();
    //
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    int week = cal.get(Calendar.DAY_OF_WEEK);
    //
    if (week == 7) {
        week = 0;
    }
    //logger.debug("week:{}",week);
    //
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    // ()?
    GregorianCalendar gc = new GregorianCalendar();
    // ??
    gc.setTime(new Date());
    // ??
    gc.add(5, -week);
    // 
    String beginDate = sdf.format(gc.getTime());
    String endDate = sdf.format(new Date());
    SimpleDateFormat sdf1 = new SimpleDateFormat("MMdd");
    String beginDate1 = sdf1.format(gc.getTime());
    String endDate1 = sdf1.format(new Date());
    //logger.debug("beginDate:{},endDate:{}",beginDate,endDate);
    manager manager = managerService.selectByPrimaryKey(1);
    List<Map<String, Object>> monthList = salaryService.getMoneyList("", "", endDate);
    List<Map<String, Object>> weekList = salaryService.getMoneyList(beginDate, endDate, "");
    List<Map<String, Object>> totleList = salaryService.getMoneyList("", "", "");

    map.put("salary", manager.getSalary());
    map.put("monthList", monthList);
    map.put("weekList", weekList);
    map.put("totleList", totleList);
    map.put("weekDate", beginDate1 + "-" + endDate1);
    return map;
}

From source file:es.tid.fiware.rss.controller.SettlementController.java

/**
 * Do settlement./*from   w ww  .  j  a v a  2  s.co  m*/
 * 
 * @param dateFrom
 * @param dateTo
 * @param aggregatorId
 * @param model
 * @return the model and view
 */
@RequestMapping(value = "/doSettlement", headers = "Accept=*/*", produces = "application/json")
@ResponseBody
public JsonResponse doSettlement(@QueryParam("dateFrom") String dateFrom, @QueryParam("dateTo") String dateTo,
        @QueryParam("aggregatorId") String aggregatorId, @QueryParam("providerId") String providerId,
        ModelMap model) {
    try {
        logger.debug("doSettlement - Provider: {} , aggregator: {}", providerId, aggregatorId);
        logger.debug("doSettlement - Start: Init" + dateFrom + ",End:" + dateTo);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
        SimpleDateFormat getDate = new SimpleDateFormat("MM/yyyy");
        String initDate = "";
        String endDate = "";
        if (dateFrom != null && !"".equalsIgnoreCase(dateFrom) && dateTo != null
                && !"".equalsIgnoreCase(dateTo)) {
            Date from = getDate.parse(dateFrom);
            Date to = getDate.parse(dateTo);
            initDate = format.format(from);
            endDate = format.format(to);
        } else {
            // By default use the current month
            GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance();
            cal.setTime(new Date());
            cal.set(Calendar.DAY_OF_MONTH, 1);
            initDate = format.format(cal.getTime());
            cal.add(Calendar.MONTH, 1);
            endDate = format.format(cal.getTime());
        }
        // Calculate settlement.
        settlementManager.runSettlement(initDate, endDate, aggregatorId, providerId);
        JsonResponse response = new JsonResponse();
        response.setMessage("Settlement proccess launched correctly.");
        response.setSuccess(true);
        return response;

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        JsonResponse response = new JsonResponse();
        response.setMessage(e.getMessage());
        response.setSuccess(false);
        return response;
    }
}

From source file:eu.europa.esig.dss.tsl.service.TSLParser.java

private Date convertToDate(XMLGregorianCalendar gregorianCalendar) {
    if (gregorianCalendar != null) {
        GregorianCalendar toGregorianCalendar = gregorianCalendar.toGregorianCalendar();
        if (toGregorianCalendar != null) {
            return toGregorianCalendar.getTime();
        }/*from w  w w  . ja va2s. co  m*/
    }
    return null;
}

From source file:com.enonic.cms.core.search.builder.ContentIndexDataFactoryTest.java

private ContentDocument createTestContent() throws Exception {
    final GregorianCalendar date = new GregorianCalendar(2011, Calendar.JANUARY, 10);

    ContentDocument content = new ContentDocument(new ContentKey(1));
    content.setCategoryKey(new CategoryKey(2));
    content.setCategoryName("MyCategory");
    content.setContentTypeKey(new ContentTypeKey(3));
    content.setContentTypeName("MyContentType");

    content.setCreated(date.getTime());
    content.setTimestamp(date.getTime());
    content.setModified(date.getTime());

    content.setTitle("MyTitle");
    content.setStatus(2);/*from   w ww  . j  a v a  2 s  .c o m*/
    content.setPriority(1);
    content.setLanguageCode("en");

    content.setModifierKey("10");
    content.setModifierName("ModifierName");
    content.setModifierQualifiedName("ModifierQName");

    content.setOwnerKey("11");
    content.setOwnerName("OwnerName");
    content.setOwnerQualifiedName("OwnerQName");

    content.setAssigneeKey("12");
    content.setAssigneeName("AssigneeName");
    content.setAssigneeQualifiedName("AssigneeQName");

    content.setAssignerKey("14");
    content.setAssignerName("AssignerName");
    content.setAssignerQualifiedName("AssignerQName");

    date.add(Calendar.MONTH, 1);
    content.setAssignmentDueDate(date.getTime());

    content.setPublishFrom(date.getTime());
    date.add(Calendar.MONTH, 1);
    content.setPublishTo(date.getTime());

    content.setContentLocations(new ContentLocations(new ContentEntity()));

    content.addUserDefinedField("data/person/age", "38");
    content.addUserDefinedField("data/person/gender", "male");
    content.addUserDefinedField("data/person/description", "description 38");

    content.addUserDefinedField("data/person/age", "28");
    content.addUserDefinedField("data/person/gender", "male");
    content.addUserDefinedField("data/person/description", "description 28");

    content.addUserDefinedField("data/person/age", "10");
    content.addUserDefinedField("data/person/gender", "male");
    content.addUserDefinedField("data/person/description", "description 10");

    return content;
}

From source file:main.UIController.java

/************ OTHER *****************/

private String gregorianToString(GregorianCalendar gcal) {
    SimpleDateFormat sdf = new SimpleDateFormat("EEEEEEEE, MMMMMMMMM d, yyyy");
    String gstr = sdf.format(gcal.getTime());
    return gstr;/*from   ww  w.j  a va  2  s .  com*/
}

From source file:org.apache.fulcrum.security.spi.AbstractUserManager.java

/**
 * Utility method that sets the user's password expiry date.
 * @param user The user whose password is to be changed.
 *
 * @author richard.brooks//w ww.  ja  va  2s  . c  o m
 * Created on Jan 16, 2006
 */
private void setPasswordExpiry(User user) {
    Calendar date = Calendar.getInstance();
    GregorianCalendar passwordExpiry = new GregorianCalendar(date.get(Calendar.YEAR), date.get(Calendar.MONTH),
            date.get(Calendar.DAY_OF_MONTH));
    passwordExpiry.add(Calendar.DAY_OF_MONTH, getPasswordDurationDays());
    user.setPasswordExpiryDate(passwordExpiry.getTime());
}

From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java

/**
 * Set the view to WEEK.//  w  ww  .  j  a  v a2 s . com
 */
private void setWeekView() {

    actualStart = (GregorianCalendar) actualDay.clone();
    actualStart.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    actualStart.set(Calendar.HOUR_OF_DAY, 0);
    actualStart.set(Calendar.MINUTE, 0);

    actualEnd = (GregorianCalendar) actualDay.clone();
    actualEnd.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    actualEnd.set(Calendar.HOUR_OF_DAY, 23);
    actualEnd.set(Calendar.MINUTE, 59);

    actualStart.add(Calendar.HOUR_OF_DAY, -1);
    actualEnd.add(Calendar.HOUR_OF_DAY, 1);

    actualView = WEEK;

    GregorianCalendar helper = (GregorianCalendar) actualEnd.clone();
    helper.add(Calendar.DATE, -1);

    makeChart(LocalizedStrings.getGeneralStrings().calendarWeekAbbreviation() + " "
            + new SimpleDateFormat("ww yyyy").format(helper.getTime()));
}

From source file:com.intel.xdk.cache.Cache.java

private void setCookie(String cookieName, String cookieValue, int expires, boolean setExpired) {
    //set value//w ww  . ja  v  a  2 s . c o m
    SharedPreferences settings = activity.getSharedPreferences(cookies, 0);
    SharedPreferences.Editor editor = settings.edit();
    editor.putString(cookieName, cookieValue);
    editor.commit();
    //set expires
    settings = activity.getSharedPreferences(cookiesExpires, 0);
    editor = settings.edit();
    if (setExpired || expires >= 0) {
        GregorianCalendar now = new GregorianCalendar();
        now.add(Calendar.DATE, expires);
        editor.putString(cookieName, sdf.format(now.getTime()));
    } else {
        editor.putString(cookieName, DONOTEXPIRE);
    }
    editor.commit();
}