Example usage for java.util Calendar setTimeInMillis

List of usage examples for java.util Calendar setTimeInMillis

Introduction

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

Prototype

public void setTimeInMillis(long millis) 

Source Link

Document

Sets this Calendar's current time from the given long value.

Usage

From source file:com.radvision.icm.service.vcm.ICMService.java

private static RecurrenceInfo convertToRecurringInfo(RecurringMeetingInfo rmi, List<String> listTerminalId,
        boolean isCreating) throws Exception {

    RecurrenceInfo ri = new RecurrenceInfo();

    ConferenceInfo info = new ConferenceInfo();
    info.setConferenceId(isCreating ? null : rmi.getRadRecurrenceId());
    info.setUserID(rmi.getUserId());/*from   w w w .  j  a  v a 2 s.c  om*/
    info.setOrgID(rmi.getMemberId());
    info.setDialableConferenceId(rmi.getDialableNumber());
    long startTime = rmi.getStartTime();
    long endTime = startTime + rmi.getTimeLong() * 60000;
    info.setStartTime(startTime);
    info.setEndTime(endTime);
    info.setMeetingTypeId(rmi.getServiceTemplateId());
    info.setDescription(rmi.getDescription());
    info.setPassword(rmi.getPassword());
    info.setFullControlPassword(rmi.getControlPin());
    int reservedport = rmi.getPortsNum() == null ? 2 : rmi.getPortsNum();
    info.setReservedIPPorts(reservedport);
    // info.setReservedISDNPorts(reservedport);
    info.setSubject(rmi.getSubject());
    if (listTerminalId != null && listTerminalId.size() > 0) {
        List<TerminalInfo> terminals = info.getTerminals();
        for (int i = 0; i < listTerminalId.size(); i++) {
            TerminalInfo ti = new TerminalInfo();
            ti.setTerminalId(listTerminalId.get(i));
            terminals.add(ti);
        }
    }
    ri.setConferenceInfoTemplate(info);

    List<RecurInstanceInfo> riis = ri.getRecurInstanceInfos();
    if (rmi.getRecurrenceType() == RecurringMeetingInfo.RECURRING_DAILY) {
        int interval = rmi.getDayInterval();
        long currTime = System.currentTimeMillis();
        long nextTime = (startTime > currTime) ? startTime : currTime;
        rmi.setStartDate(getCurrentDate(nextTime));
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(nextTime);
        if (rmi.getEndType() == RecurringMeetingInfo.RECURRING_ENDTYPE_DATE) {
            long endDate = rmi.getEndDate();
            rmi.setEndDate(getCurrentDate(endDate));
            while (nextTime < endDate) {
                if (interval <= 0) {
                    int weekDay = cal.get(Calendar.DAY_OF_WEEK);
                    if (weekDay == 0 && weekDay == 6) {
                        cal.add(Calendar.DAY_OF_YEAR, 1);
                        nextTime = cal.getTimeInMillis();
                        continue;
                    }
                }
                RecurInstanceInfo rii = new RecurInstanceInfo();
                rii.setStartTime(nextTime);
                rii.setEndTime(nextTime + rmi.getTimeLong() * 60000);
                riis.add(rii);
                cal.add(Calendar.DAY_OF_YEAR, interval <= 0 ? 1 : interval);
                nextTime = cal.getTimeInMillis();
            }
        } else {
            int repeat = rmi.getEndAfterNumber();
            int i = 0;
            while (i < repeat) {
                if (interval <= 0) {
                    int weekDay = cal.get(Calendar.DAY_OF_WEEK);
                    if (weekDay == 0 && weekDay == 6) {
                        cal.add(Calendar.DAY_OF_YEAR, 1);
                        nextTime = cal.getTimeInMillis();
                        continue;
                    }
                }
                RecurInstanceInfo rii = new RecurInstanceInfo();
                rii.setStartTime(nextTime);
                rii.setEndTime(nextTime + rmi.getTimeLong() * 60000);
                riis.add(rii);
                i++;
                if (i >= repeat) {
                    rmi.setEndDate(getCurrentDate(nextTime));
                    break;
                }
                cal.add(Calendar.DAY_OF_YEAR, interval <= 0 ? 1 : interval);
                nextTime = cal.getTimeInMillis();
            }
        }
    } else if (rmi.getRecurrenceType() == RecurringMeetingInfo.RECURRING_WEEKLY) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(startTime);
        int startDay = cal.get(Calendar.DAY_OF_WEEK);
        cal.add(Calendar.DAY_OF_YEAR, rmi.getWeekDay() - startDay);
        startTime = cal.getTimeInMillis();
        long currTime = System.currentTimeMillis();
        long nextTime = startTime;
        int interval = rmi.getWeekInterval();
        if (startTime < currTime) {
            cal.add(Calendar.DAY_OF_YEAR, 7 * interval);
            nextTime = cal.getTimeInMillis();
        }
        rmi.setStartDate(getCurrentDate(nextTime));
        if (rmi.getEndType() == RecurringMeetingInfo.RECURRING_ENDTYPE_DATE) {
            long endDate = rmi.getEndDate();
            rmi.setEndDate(getCurrentDate(endDate));
            while (nextTime < endDate) {
                if (interval <= 0) {
                    int weekDay = cal.get(Calendar.DAY_OF_WEEK);
                    if (weekDay == 0 && weekDay == 6) {
                        cal.add(Calendar.DAY_OF_YEAR, 1);
                        nextTime = cal.getTimeInMillis();
                        continue;
                    }
                }
                RecurInstanceInfo rii = new RecurInstanceInfo();
                rii.setStartTime(nextTime);
                rii.setEndTime(nextTime + rmi.getTimeLong() * 60000);
                riis.add(rii);
                cal.add(Calendar.DAY_OF_YEAR, interval <= 0 ? 1 : interval);
                nextTime = cal.getTimeInMillis();
            }
        } else {
            int repeat = rmi.getEndAfterNumber();
            int i = 0;
            while (i < repeat) {
                if (interval <= 0) {
                    int weekDay = cal.get(Calendar.DAY_OF_WEEK);
                    if (weekDay == 0 && weekDay == 6) {
                        cal.add(Calendar.DAY_OF_YEAR, 1);
                        nextTime = cal.getTimeInMillis();
                        continue;
                    }
                }
                RecurInstanceInfo rii = new RecurInstanceInfo();
                rii.setStartTime(nextTime);
                rii.setEndTime(nextTime + rmi.getTimeLong() * 60000);
                riis.add(rii);
                i++;
                if (i >= repeat) {
                    rmi.setEndDate(getCurrentDate(nextTime));
                    break;
                }
                cal.add(Calendar.DAY_OF_YEAR, interval <= 0 ? 1 : interval * 7);
                nextTime = cal.getTimeInMillis();
            }
        }
    } else { //per month
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(startTime);
        int startDay = cal.get(Calendar.DAY_OF_MONTH);
        int monthDay = rmi.getMonthDay();
        if (monthDay > 0) {
            cal.add(Calendar.DAY_OF_YEAR, rmi.getMonthDay() - startDay);
            startTime = cal.getTimeInMillis();
            long currTime = System.currentTimeMillis();
            long nextTime = startTime;
            int interval = rmi.getMonthInterval();
            if (startTime < currTime) {
                cal.add(Calendar.MONTH, interval);
                nextTime = cal.getTimeInMillis();
            }
            rmi.setStartDate(getCurrentDate(nextTime));
            if (rmi.getEndType() == RecurringMeetingInfo.RECURRING_ENDTYPE_DATE) {
                long endDate = rmi.getEndDate();
                rmi.setEndDate(getCurrentDate(endDate));
                while (nextTime < endDate) {
                    RecurInstanceInfo rii = new RecurInstanceInfo();
                    rii.setStartTime(nextTime);
                    rii.setEndTime(nextTime + rmi.getTimeLong() * 60000);
                    riis.add(rii);
                    cal.add(Calendar.MONTH, interval);
                    nextTime = cal.getTimeInMillis();
                }
            } else {
                int repeat = rmi.getEndAfterNumber();
                int i = 0;
                while (i < repeat) {
                    RecurInstanceInfo rii = new RecurInstanceInfo();
                    rii.setStartTime(nextTime);
                    rii.setEndTime(nextTime + rmi.getTimeLong() * 60000);
                    riis.add(rii);
                    i++;
                    if (i >= repeat) {
                        rmi.setEndDate(getCurrentDate(nextTime));
                        break;
                    }
                    cal.add(Calendar.MONTH, interval);
                    nextTime = cal.getTimeInMillis();
                }
            }
        } else {
            cal.set(Calendar.DAY_OF_MONTH, 1);
            cal.add(Calendar.MONTH, 1);
            cal.add(Calendar.DAY_OF_YEAR, monthDay);
            startTime = cal.getTimeInMillis();
            long currTime = System.currentTimeMillis();
            long nextTime = startTime;
            int interval = rmi.getMonthInterval();
            if (startTime < currTime) {
                cal.set(Calendar.DAY_OF_MONTH, 1);
                cal.add(Calendar.MONTH, interval + 1);
                cal.add(Calendar.DAY_OF_YEAR, monthDay);
                nextTime = cal.getTimeInMillis();
            }
            rmi.setStartDate(getCurrentDate(nextTime));
            if (rmi.getEndType() == RecurringMeetingInfo.RECURRING_ENDTYPE_DATE) {
                long endDate = rmi.getEndDate();
                rmi.setEndDate(getCurrentDate(endDate));
                while (nextTime < endDate) {
                    RecurInstanceInfo rii = new RecurInstanceInfo();
                    rii.setStartTime(nextTime);
                    rii.setEndTime(nextTime + rmi.getTimeLong() * 60000);
                    riis.add(rii);
                    cal.add(Calendar.MONTH, interval + 1);
                    cal.add(Calendar.DAY_OF_YEAR, monthDay);
                    nextTime = cal.getTimeInMillis();
                }
            } else {
                int repeat = rmi.getEndAfterNumber();
                int i = 0;
                while (i < repeat) {
                    RecurInstanceInfo rii = new RecurInstanceInfo();
                    rii.setStartTime(nextTime);
                    rii.setEndTime(nextTime + rmi.getTimeLong() * 60000);
                    riis.add(rii);
                    i++;
                    if (i >= repeat) {
                        rmi.setEndDate(getCurrentDate(nextTime));
                        break;
                    }
                    cal.set(Calendar.DAY_OF_MONTH, 1);
                    cal.add(Calendar.MONTH, interval + 1);
                    cal.add(Calendar.DAY_OF_YEAR, monthDay);
                    nextTime = cal.getTimeInMillis();
                }
            }
        }
    }
    //      ri.getRecurInstanceInfos().add(rii);
    return ri;
}

From source file:com.adobe.communities.ugc.migration.importer.UGCImportHelper.java

private static void createTally(final ModifyingResourceProvider srp, final Resource post,
        final String tallyType, final String userIdentifier, final Long timestamp, final String response,
        final TallyOperationsService tallyOperationsService) throws PersistenceException {

    final ResourceResolver resolver = post.getResourceResolver();
    final Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("jcr:primaryType", "social:asiResource");
    final Calendar calendar = new GregorianCalendar();
    calendar.setTimeInMillis(timestamp);
    properties.put("jcr:created", calendar.getTime());
    Resource tallyResource = null;
    Tally tally;/*from  w ww.  j ava 2  s  . c  o  m*/
    if (tallyType.equals(TallyOperationsService.VOTING)) {
        if (post.getResourceType().equals(VotingSocialComponent.VOTING_RESOURCE_TYPE)) {
            tallyResource = post;
        } else {
            Iterable<Resource> postChildren = post.getChildren();
            for (final Resource postChild : postChildren) {
                if (postChild.getResourceType().equals(VotingSocialComponent.VOTING_RESOURCE_TYPE)) {
                    tallyResource = postChild;
                    break;
                }
            }
            if (tallyResource == null) {
                properties.put("sling:resourceType", VotingSocialComponent.VOTING_RESOURCE_TYPE);
                properties.put("social:parentid", post.getPath());
                tallyResource = resolver.create(post, "voting", properties);
                try {
                    resolver.commit();
                } catch (Exception e) {
                    // ignoring exception to let the rest of the file get imported
                    LOG.error("Could not create vote {} on post {}", tallyResource, post);
                }
                properties.remove("sling:resourceType");
            }
        }
        tally = tallyResource.adaptTo(Voting.class);
        tally.setTallyResourceType(VotingSocialComponent.VOTING_RESOURCE_TYPE);
    } else if (tallyType.equals(TallyOperationsService.POLL)) {
        // don't throw an exception, since we know what it is, but log a warning since we no longer support polls
        LOG.warn("Unsupported tally type 'poll' could not be imported");
        return;
    } else if (tallyType.equals(TallyOperationsService.RATING)) {
        if (post.getResourceType().equals(RatingSocialComponent.RATING_RESOURCE_TYPE)) {
            tallyResource = post;
        } else {
            Iterable<Resource> postChildren = post.getChildren();
            for (final Resource postChild : postChildren) {
                if (postChild.getResourceType().equals(RatingSocialComponent.RATING_RESOURCE_TYPE)) {
                    tallyResource = postChild;
                    break;
                }
            }
            if (tallyResource == null) {
                properties.put("sling:resourceType", RatingSocialComponent.RATING_RESOURCE_TYPE);
                tallyResource = srp.create(resolver, post.getPath() + "/rating_" + randomHexString(),
                        properties);
                srp.commit(resolver);
                properties.remove("sling:resourceType");
            }
        }
        tally = tallyResource.adaptTo(Voting.class);
        tally.setTallyResourceType(RatingSocialComponent.RATING_RESOURCE_TYPE);
    } else {
        throw new RuntimeException("unrecognized tally type");
    }
    // Needed params:
    try {
        properties.put(TallyConstants.TIMESTAMP_PROPERTY, calendar);
        tallyOperationsService.setTallyResponse(tally.getTallyTarget(), userIdentifier,
                resolver.adaptTo(Session.class), response, tallyType, properties);
    } catch (final OperationException e) {
        throw new RuntimeException("Unable to set the tally response value: " + e.getMessage(), e);
    } catch (final IllegalArgumentException e) {
        // We can ignore this. It means that the value set for the response in the migrated data is no longer
        // valid. This happens for "#neutral#" which used to be a valid response, but was taken out in later
        // versions.
    }
}

From source file:arc.noaa.weather.activities.MainActivity.java

public static String formatTimeWithDayIfNotToday(Context context, long timeInMillis) {
    Calendar now = Calendar.getInstance();
    Calendar lastCheckedCal = new GregorianCalendar();
    lastCheckedCal.setTimeInMillis(timeInMillis);
    Date lastCheckedDate = new Date(timeInMillis);
    String timeFormat = android.text.format.DateFormat.getTimeFormat(context).format(lastCheckedDate);
    if (now.get(Calendar.YEAR) == lastCheckedCal.get(Calendar.YEAR)
            && now.get(Calendar.DAY_OF_YEAR) == lastCheckedCal.get(Calendar.DAY_OF_YEAR)) {
        // Same day, only show time
        return timeFormat;
    } else {/*w w  w  .j  av  a2 s. c o  m*/
        return android.text.format.DateFormat.getDateFormat(context).format(lastCheckedDate) + " " + timeFormat;
    }
}

From source file:com.adobe.communities.ugc.migration.importer.UGCImportHelper.java

protected static void importTranslation(final JsonParser jsonParser, final Resource post) throws IOException {
    JsonToken token = jsonParser.getCurrentToken();
    final Map<String, Object> properties = new HashMap<String, Object>();
    if (token != JsonToken.START_OBJECT) {
        throw new IOException("expected a start object token, got " + token.asString());
    }//w w  w.  j a v a 2  s .c  om
    properties.put("jcr:primaryType", "social:asiResource");
    Resource translationFolder = null;
    token = jsonParser.nextToken();
    while (token == JsonToken.FIELD_NAME) {
        token = jsonParser.nextToken(); //advance to the field value
        if (jsonParser.getCurrentName().equals((ContentTypeDefinitions.LABEL_TRANSLATIONS))) {
            if (null == translationFolder) {
                // begin by creating the translation folder resource
                translationFolder = post.getResourceResolver().create(post, "translation", properties);
            }
            //now check to see if any translations exist
            if (token == JsonToken.START_OBJECT) {
                token = jsonParser.nextToken();
                if (token == JsonToken.FIELD_NAME) {
                    while (token == JsonToken.FIELD_NAME) { // each new field represents another translation
                        final Map<String, Object> translationProperties = new HashMap<String, Object>();
                        translationProperties.put("jcr:primaryType", "social:asiResource");
                        String languageLabel = jsonParser.getCurrentName();
                        token = jsonParser.nextToken();
                        if (token != JsonToken.START_OBJECT) {
                            throw new IOException("expected a start object token for translation item, got "
                                    + token.asString());
                        }
                        token = jsonParser.nextToken();
                        while (token != JsonToken.END_OBJECT) {
                            jsonParser.nextToken(); //get next field value
                            if (jsonParser.getCurrentName()
                                    .equals(ContentTypeDefinitions.LABEL_TIMESTAMP_FIELDS)) {
                                jsonParser.nextToken(); // advance to first field name
                                while (!jsonParser.getCurrentToken().equals(JsonToken.END_ARRAY)) {
                                    final String timestampLabel = jsonParser.getValueAsString();
                                    if (translationProperties.containsKey(timestampLabel)) {
                                        final Calendar calendar = new GregorianCalendar();
                                        calendar.setTimeInMillis(Long
                                                .parseLong((String) translationProperties.get(timestampLabel)));
                                        translationProperties.put(timestampLabel, calendar.getTime());
                                    }
                                    jsonParser.nextToken();
                                }
                            } else if (jsonParser.getCurrentName()
                                    .equals(ContentTypeDefinitions.LABEL_SUBNODES)) {
                                jsonParser.skipChildren();
                            } else {
                                translationProperties.put(jsonParser.getCurrentName(),
                                        URLDecoder.decode(jsonParser.getValueAsString(), "UTF-8"));
                            }
                            token = jsonParser.nextToken(); //get next field label
                        }
                        // add the language-specific translation under the translation folder resource
                        Resource translation = post.getResourceResolver().create(post.getChild("translation"),
                                languageLabel, translationProperties);
                        if (null == translation) {
                            throw new IOException("translation not actually imported");
                        }
                    }
                    jsonParser.nextToken(); //skip END_OBJECT token for translation
                } else if (token == JsonToken.END_OBJECT) {
                    // no actual translation to import, so we're done here
                    jsonParser.nextToken();
                }
            } else {
                throw new IOException(
                        "expected translations to be contained in an object, saw instead: " + token.asString());
            }
        } else if (jsonParser.getCurrentName().equals("mtlanguage")
                || jsonParser.getCurrentName().equals("jcr:createdBy")) {
            properties.put(jsonParser.getCurrentName(), jsonParser.getValueAsString());
        } else if (jsonParser.getCurrentName().equals("jcr:created")) {
            final Calendar calendar = new GregorianCalendar();
            calendar.setTimeInMillis(jsonParser.getLongValue());
            properties.put("jcr:created", calendar.getTime());
        }
        token = jsonParser.nextToken();
    }
    if (null == translationFolder && properties.containsKey("mtlanguage")) {
        // it's possible that no translations existed, so we need to make sure the translation resource (which
        // includes the original post's detected language) is created anyway
        post.getResourceResolver().create(post, "translation", properties);
    }
}

From source file:lu.lippmann.cdb.common.gui.ts.TimeSeriesChartUtil.java

private static void fillWithSingleAxis(final Instances dataSet, final int dateIdx,
        final TimeSeriesCollection tsDataset) {
    final int numInstances = dataSet.numInstances();

    final Calendar cal = Calendar.getInstance();
    for (final Integer i : WekaDataStatsUtil.getNumericAttributesIndexes(dataSet)) {
        if (dataSet.attributeStats(i).missingCount == dataSet.numInstances()) {
            System.out.println("TimeSeriesChartUtil: Only missing values for '" + dataSet.attribute(i).name()
                    + "', so skip it!");
            continue;
        }/*from  ww w . ja v a2  s .  c o m*/
        final TimeSeries ts = new TimeSeries(dataSet.attribute(i).name());
        for (int k = 0; k < numInstances; k++) {
            final Instance instancek = dataSet.instance(k);
            final long timeInMilliSec = (long) instancek.value(dateIdx);
            cal.setTimeInMillis(timeInMilliSec);

            if (instancek.isMissing(i)) {
                ts.addOrUpdate(new Millisecond(cal.getTime()), null);
            } else {
                ts.addOrUpdate(new Millisecond(cal.getTime()), instancek.value(i));
            }
        }
        if (!ts.isEmpty())
            tsDataset.addSeries(ts);
    }
}

From source file:edu.harvard.i2b2.analysis.dataModel.TimelineFactory.java

public static String GetTimelineHeader() {
    Calendar cldr = Calendar.getInstance(TimeZone.getDefault());
    cldr.setTimeInMillis(System.currentTimeMillis());
    String todayStr = (cldr.get(Calendar.MONTH) + 1) + "-" + cldr.get(Calendar.DAY_OF_MONTH) + "-"
            + cldr.get(Calendar.YEAR);
    return "%beforeSeptember1997" + newline + "%today," + /*5-02-2006*/todayStr + " 12:00" + newline + newline +

            "%c, Available colors:" + newline + "%c, " + newline + "%c, (\"seagreen\",          \"2e8b57\");"
            + newline + "%c, (\"seashell\",          \"fff5ee\");" + newline
            + "%c, (\"sienna\",            \"a0522d\");" + newline + "%c, (\"skyblue\",           \"87ceeb\");"
            + newline + "%c, (\"slateblue\",         \"6a5acd\");" + newline
            + "%c, (\"slategray\",         \"708090\");" + newline + "%c, (\"slategrey\",         \"708090\");"
            + newline + "%c, (\"snow\",              \"fffafa\");" + newline
            + "%c, (\"springgreen\",       \"00ff7f\");" + newline + "%c, (\"steelblue\",         \"4682b4\");"
            + newline + "%c, (\"tan\",               \"d2b48c\");" + newline
            + "%c, (\"thistle\",           \"d8bfd8\");" + newline + "%c, (\"tomato\",            \"ff6347\");"
            + newline + "%c, (\"turquoise\",         \"40e0d0\");" + newline
            + "%c, (\"violet\",            \"ee82ee\");" + newline + "%c, (\"violetred\",         \"d02090\");"
            + newline + "%c, (\"wheat\",             \"f5deb3\");" + newline
            + "%c, (\"white\",             \"ffffff\");" + newline + "%c, (\"whitesmoke\",        \"f5f5f5\");"
            + newline + "%c, (\"yellow\",            \"ffff00\");" + newline
            + "%c, (\"yellowgreen\",       \"9acd32\");" + newline + "%c, (\"lightbrown\",        \"fff5c8\");"
            + newline + "%c, (\"darkbrown\",         \"ffecaf\");" + newline + newline +

            "%person,i2b2 Timeline Application,.," + cldr.get(Calendar.YEAR)/*2007*/ + ",.,images/cath.gif"
            + newline + newline +// w  w w .j a  v  a  2  s. co m

            "%c,PERSON 1" + newline;
}

From source file:com.krawler.common.util.BaseStringUtil.java

public static Date stdNewDate(String tzDiff) {
    Calendar cal = Calendar.getInstance();
    Calendar cal1 = new GregorianCalendar(TimeZone.getTimeZone("GMT" + tzDiff));
    try {//from   www . j  a  v  a  2s. c o  m
        Date dt = new Date();
        cal1.setTimeInMillis(dt.getTime());
        cal.set(Calendar.YEAR, cal1.get(Calendar.YEAR));
        cal.set(Calendar.MONTH, cal1.get(Calendar.MONTH));
        cal.set(Calendar.DAY_OF_MONTH, cal1.get(Calendar.DAY_OF_MONTH));
        cal.set(Calendar.HOUR_OF_DAY, cal1.get(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE, cal1.get(Calendar.MINUTE));
        cal.set(Calendar.SECOND, cal1.get(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal1.get(Calendar.MILLISECOND));
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        return cal.getTime();
    }
}

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

public Object fromObject(Object source) {
    if (source == null) {
        return null;
    }// w w w  . j  a  v  a 2  s  .  c  o  m
    if (source instanceof Calendar) {
        return source;
    }

    Date date = (Date) ConvertUtils.convert(source.toString(), Date.class);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(date.getTime());

    return calendar;
}

From source file:com.taurus.compratae.test.ArchivoDbServiceTestCase.java

public void testBuscarTodo() {
    log.debug("Inicio testRecarga");
    setup();//from ww w.  ja  va 2s  .c om
    Date fecha1 = new Date();
    SimpleDateFormat formatoDelTexto = new SimpleDateFormat("yyyy-MM-dd");
    String fecha = formatoDelTexto.format(fecha1);

    Date fechaEnviar = null;
    try {
        fechaEnviar = formatoDelTexto.parse(fecha);
    } catch (ParseException ex) {
        ex.printStackTrace();
    }
    Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(fechaEnviar.getTime());
    cal.add(Calendar.MINUTE, 1439);
    Date fecha2 = new java.sql.Date(cal.getTimeInMillis());
    Archivo archivo = archivoDbService.buscarEntreFechas(fechaEnviar, fecha2);
    log.debug("Fin testRecarga");
}

From source file:com.prey.json.actions.Report.java

public boolean valida(Context ctx) {
    long lastReportStartDate = PreyConfig.getPreyConfig(ctx).getLastReportStartDate();
    PreyLogger.d("last:" + lastReportStartDate);
    if (lastReportStartDate != 0) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(lastReportStartDate);
        cal.add(Calendar.MINUTE, 1);
        long timeMore = cal.getTimeInMillis();
        PreyLogger.d("timM:" + timeMore);
        Date nowDate = new Date();
        long now = nowDate.getTime();
        PreyLogger.d("now_:" + now);
        PreyLogger.d("now>=timeMore:" + (now >= timeMore));
        return (now >= timeMore);
    }//from  w  w  w  .j  ava  2s. c  o  m
    return true;
}