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.whizzosoftware.hobson.scheduler.ical.ICalTask.java

public List<Long> getRunsDuringInterval(long startTime, long endTime) throws SchedulingException {
    List<Long> results = new ArrayList<>();
    if (event != null) {
        // if there's a solar offset, reset the start time to the beginning of the day so that
        // we can see if the event should run at any point during the first to subsequent days
        if (solarOffset != null) {
            if (latitude == null || longitude == null) {
                throw new SchedulingException(
                        "Unable to calculate sunrise/sunset; please set Hub latitude/longitude");
            }/* w  w  w .ja v  a 2s. c  om*/
            Calendar c = Calendar.getInstance();
            c.setTimeInMillis(startTime);
            DateHelper.resetToBeginningOfDay(c);
            startTime = c.getTimeInMillis();
        }

        PeriodList periods = event
                .calculateRecurrenceSet(new Period(new DateTime(startTime), new DateTime(endTime)));
        for (Object period : periods) {
            // get the recurrence time
            long time = ((Period) period).getStart().getTime();

            // adjust time if there's an solar offset defined
            if (solarOffset != null) {
                Calendar c = Calendar.getInstance();
                c.setTimeInMillis(time);
                try {
                    c = SolarHelper.createCalendar(c, solarOffset, latitude, longitude);
                    time = c.getTimeInMillis();
                } catch (ParseException e) {
                    throw new SchedulingException("Error parsing solar offset", e);
                }
            }

            results.add(time);
        }
    }
    return results;
}

From source file:com.sdk.connector.chart.TimeDomainRenderer.java

@Override
public void chartMouseClicked(ChartMouseEvent cme) {
    ChartEntity chartentity = cme.getEntity();
    //JOptionPane.showMessageDialog(null,chartentity.getClass(), "",JOptionPane.CANCEL_OPTION);

    if (cme.getEntity() instanceof PlotEntity) {
        if (chartentity != null) {
            Point2D p = chartPanel.translateScreenToJava2D(cme.getTrigger().getPoint());
            final Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
            double chartX = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge());
            double chartY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge());

            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis((long) chartX);
            createAnnotation(formatter.format(calendar.getTime()), chartX, chartY);
        } else {//from ww w. ja  v a 2s  . co  m

        }
    }
}

From source file:com.linkedin.drelephant.mapreduce.fetchers.MapReduceFSFetcherHadoop2.java

/**
 * The location of a job history file is in format: {done-dir}/yyyy/mm/dd/{serialPart}.
 * yyyy/mm/dd is the year, month and date of the finish time.
 * serialPart is the first 6 digits of the serial number considering it as a 9 digits number.
 * PS: The serial number is the last part of an app id.
 * <p>//from   www  .  j av a 2s. c  o m
 * For example, if appId = application_1461566847127_84624, then serial number is 84624.
 * Consider it as a 9 digits number, serial number is 000084624. So the corresponding
 * serialPart is 000084. If this application finish at 2016-5-30, its history file will locate
 * at {done-dir}/2016/05/30/000084
 * </p>
 * <p>
 * Furthermore, this location format is only satisfied for finished jobs in {done-dir} and not
 * for running jobs in {intermediate-done-dir}.
 * </p>
 */
protected String getHistoryDir(AnalyticJob job) {
    // generate the date part
    Calendar timestamp = Calendar.getInstance();
    timestamp.setTimeInMillis(job.getFinishTime());
    String datePart = String.format(TIMESTAMP_DIR_FORMAT, timestamp.get(Calendar.YEAR),
            timestamp.get(Calendar.MONTH) + 1, timestamp.get(Calendar.DAY_OF_MONTH));

    // generate the serial part
    String appId = job.getAppId();
    int serialNumber = Integer.parseInt(appId.substring(appId.lastIndexOf('_') + 1));
    String serialPart = String.format("%09d", serialNumber).substring(0, SERIAL_NUMBER_DIRECTORY_DIGITS);

    return StringUtils.join(new String[] { _historyLocation, datePart, serialPart, "" }, File.separator);
}

From source file:com.projity.server.data.mspdi.ModifiedMSPDIWriter.java

/**
 * This method writes data for a single assignment to an MSPDI file.
 *
 * @param factory/*from   ww w .j  a  v a 2  s . c  o  m*/
 *            ObjectFactory instance
 * @param mpx
 *            Resource assignment data
 * @param uid
 *            Unique ID for the new assignment
 * @return New MSPDI assignment instance
 * @throws JAXBException
 *             on xml creation errors
 */
protected Project.AssignmentsType.AssignmentType writeAssignment(ObjectFactory factory, ResourceAssignment mpx,
        int uid) throws JAXBException {
    Project.AssignmentsType.AssignmentType xml = super.writeAssignment(factory, mpx, uid);

    //Microsoft Project does something strange: The unassigned resource has a 0 id for the resource, but assignments use the (short)-1 value.
    if (mpx.getResourceID() == 0)
        xml.setResourceUID(BigInteger.valueOf(EnterpriseResource.UNASSIGNED_ID));

    Assignment projityAssignment = (Assignment) projityAssignmentMap.get(mpx);
    Calendar stop = DateTime.calendarInstance();
    stop.setTimeInMillis(projityAssignment.getStop());
    xml.setStop(stop);
    Calendar resume = DateTime.calendarInstance();
    resume.setTimeInMillis(projityAssignment.getResume());
    xml.setResume(resume);
    writeAssigmentBaselinesAndTimephased(factory, xml, mpx, uid);

    return (xml);
}

From source file:com.hihframework.core.utils.DateUtils.java

/**
 * ????/*  w w  w  . j  a v a 2s . com*/
 * ?XX-XX????XX-XX?
 *
 * @param startTime 
 * @param endTime   ?
 * @return 
 */
public static String getTimeSlice(Timestamp startTime, Timestamp endTime) {

    String rtn = "";

    Calendar caleStart = Calendar.getInstance();
    Calendar caleEnd = Calendar.getInstance();
    caleStart.setTimeInMillis(startTime.getTime());
    caleEnd.setTimeInMillis(endTime.getTime());

    String dayStart = caleStart.get(Calendar.YEAR) + "" + (caleStart.get(Calendar.MONTH) + 1) + ""
            + caleStart.get(Calendar.DAY_OF_MONTH) + "";
    String dayEnd = caleEnd.get(Calendar.YEAR) + "" + (caleEnd.get(Calendar.MONTH) + 1) + ""
            + caleEnd.get(Calendar.DAY_OF_MONTH) + "";

    if (dayStart.equals(dayEnd)) {
        // ?
        rtn = caleStart.get(Calendar.HOUR_OF_DAY) + "" + caleStart.get(Calendar.MINUTE) + "-"
                + caleEnd.get(Calendar.HOUR_OF_DAY) + "" + caleEnd.get(Calendar.MINUTE) + "";
    } else {
        // ??
        rtn = (caleStart.get(Calendar.MONTH) + 1) + "" + caleStart.get(Calendar.DAY_OF_MONTH) + "" + "-"
                + (caleEnd.get(Calendar.MONTH) + 1) + "" + caleEnd.get(Calendar.DAY_OF_MONTH) + "";
    }

    caleStart = null;
    caleEnd = null;
    return rtn;
}

From source file:com.microsoft.mimickeralarm.model.Alarm.java

public void snooze() {
    Context context = AlarmApplication.getAppContext();
    // Schedule the snooze and update the alarm data with the details
    long snoozeTime = AlarmScheduler.snoozeAlarm(context, this, getAlarmSnoozeDuration());
    Calendar snoozeCalendar = Calendar.getInstance();
    snoozeCalendar.setTimeInMillis(snoozeTime);
    setSnoozeHour(snoozeCalendar.get(Calendar.HOUR_OF_DAY));
    setSnoozeMinute(snoozeCalendar.get(Calendar.MINUTE));
    setSnoozeSeconds(snoozeCalendar.get(Calendar.SECOND));
    setSnoozed(true);//from   www .  ja  va2s .  co m
    setIsEnabled(true);
    AlarmList.get(context).updateAlarm(this);
}

From source file:ddf.catalog.cache.impl.ResourceCacheTest.java

private MetacardImpl generateMetacard() throws URISyntaxException {
    MetacardImpl metacard = new MetacardImpl();
    metacard.setSourceId("source1");
    metacard.setId("id123");
    metacard.setContentTypeName("content-type-name");
    metacard.setContentTypeVersion("content-type-version");
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(1400673600); //hardcode date to ensure it is the same time.
    metacard.setCreatedDate(c.getTime());
    metacard.setEffectiveDate(c.getTime());
    metacard.setExpirationDate(c.getTime());
    metacard.setModifiedDate(c.getTime());
    metacard.setLocation("POINT(0 10)");
    metacard.setMetadata("<metadata>abc</metadata>");
    metacard.setResourceSize("100");
    metacard.setResourceURI(new URI("https://github.com/codice"));
    metacard.setTitle("title");
    return metacard;
}

From source file:com.github.mybatis.spring.MapperFactoryBean.java

/**
 * ? 2013-06-11 03:14:25/*  www. j  a  v a  2s.  c  o m*/
 *
 * @param date 
 * @return 
 */
private String formatYmdHis(Date date) {
    Calendar ca = Calendar.getInstance(CHINA_ZONE, CHINA_LOCALE);
    ca.setTimeInMillis(date.getTime());
    StringBuilder sbd = new StringBuilder();
    sbd.append(ca.get(Calendar.YEAR)).append('-');
    int month = 1 + ca.get(Calendar.MONTH);
    if (month < 10) {
        sbd.append('0');
    }
    sbd.append(month).append('-');
    int day = ca.get(Calendar.DAY_OF_MONTH);
    if (day < 10) {
        sbd.append('0');
    }
    sbd.append(day).append(' ');
    int hour = ca.get(Calendar.HOUR_OF_DAY);
    if (hour < 10) {
        sbd.append('0');
    }
    sbd.append(hour).append(':');
    int minute = ca.get(Calendar.MINUTE);
    if (minute < 10) {
        sbd.append('0');
    }
    sbd.append(minute).append(':');
    int second = ca.get(Calendar.SECOND);
    if (second < 10) {
        sbd.append('0');
    }
    sbd.append(second);
    return sbd.toString();
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgClient.CFAccXMsgClientSchema.java

public static Calendar convertTimeString(String val) {
    if ((val == null) || (val.length() == 0)) {
        return (null);
    } else if (val.length() != 8) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(CFAccXMsgClientSchema.class,
                "convertTimeString", "Value must be in HH24:MI:SS format, \"" + val + "\" is invalid");
    } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '2'))
            && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9')) && (val.charAt(2) == ':')
            && ((val.charAt(3) >= '0') && (val.charAt(3) <= '5'))
            && ((val.charAt(4) >= '0') && (val.charAt(4) <= '9')) && (val.charAt(5) == ':')
            && ((val.charAt(6) >= '0') && (val.charAt(6) <= '5'))
            && ((val.charAt(7) >= '0') && (val.charAt(7) <= '9'))) {
        /*//from  w  w  w  .j  a  v  a 2s  . c o m
         *   NOTE:
         *      .Net uses substring( startcol, lengthOfSubstring )
         *      Java uses substring( startcol, endcol ) and does not
         *         include charAt( endcol );
         */
        int hour = Integer.parseInt(val.substring(0, 2));
        int minute = Integer.parseInt(val.substring(3, 5));
        int second = Integer.parseInt(val.substring(6, 8));
        Calendar retval = new GregorianCalendar(CFLibDbUtil.getDbServerTimeZone());
        retval.set(Calendar.YEAR, 2000);
        retval.set(Calendar.MONTH, 0);
        retval.set(Calendar.DAY_OF_MONTH, 1);
        retval.set(Calendar.HOUR_OF_DAY, hour);
        retval.set(Calendar.MINUTE, minute);
        retval.set(Calendar.SECOND, second);
        Calendar local = new GregorianCalendar();
        local.setTimeInMillis(retval.getTimeInMillis());
        return (local);
    } else {
        throw CFLib.getDefaultExceptionFactory().newUsageException(CFAccXMsgClientSchema.class,
                "convertTimeString", "Value must be in HH24:MI:SS format \"" + val + "\" is invalid");
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgClient.CFAccXMsgClientSchema.java

public static Calendar convertDateString(String val) {
    if ((val == null) || (val.length() == 0)) {
        return (null);
    } else if (val.length() != 10) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(CFAccXMsgClientSchema.class,
                "convertDateString", "Value must be in YYYY-MM-DD format, \"" + val + "\" is invalid");
    } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '9'))
            && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9'))
            && ((val.charAt(2) >= '0') && (val.charAt(2) <= '9'))
            && ((val.charAt(3) >= '0') && (val.charAt(3) <= '9')) && (val.charAt(4) == '-')
            && ((val.charAt(5) >= '0') && (val.charAt(5) <= '1'))
            && ((val.charAt(6) >= '0') && (val.charAt(6) <= '9')) && (val.charAt(7) == '-')
            && ((val.charAt(8) >= '0') && (val.charAt(8) <= '3'))
            && ((val.charAt(9) >= '0') && (val.charAt(9) <= '9'))) {
        /*//from   w  w  w.  ja  v a  2s  .  c o m
         *   NOTE:
         *      .Net uses substring( startcol, lengthOfSubstring )
         *      Java uses substring( startcol, endcol ) and does not
         *         include charAt( endcol );
         */
        int year = Integer.parseInt(val.substring(0, 4));
        int month = Integer.parseInt(val.substring(5, 7));
        int day = Integer.parseInt(val.substring(8, 10));
        Calendar retval = new GregorianCalendar(CFLibDbUtil.getDbServerTimeZone());
        retval.set(Calendar.YEAR, year);
        retval.set(Calendar.MONTH, month - 1);
        retval.set(Calendar.DAY_OF_MONTH, day);
        retval.set(Calendar.HOUR_OF_DAY, 0);
        retval.set(Calendar.MINUTE, 0);
        retval.set(Calendar.SECOND, 0);
        Calendar local = new GregorianCalendar();
        local.setTimeInMillis(retval.getTimeInMillis());
        return (local);
    } else {
        throw CFLib.getDefaultExceptionFactory().newUsageException(CFAccXMsgClientSchema.class,
                "convertDateString", "Value must be in YYYY-MM-DD format, \"" + val + "\" is invalid");
    }
}