Example usage for java.util GregorianCalendar setTimeInMillis

List of usage examples for java.util GregorianCalendar setTimeInMillis

Introduction

In this page you can find the example usage for java.util GregorianCalendar 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:op.tools.SYSCalendar.java

/**
 * nimmt das bergebene Datum und setzt die Uhrzeitkomponente auf 23:59:59
 *
 * @param d/* w  w  w  . j  ava 2s .c  o m*/
 * @return das Ergebnis als TimeInMillis
 */
public static long endOfDay(Date d) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTimeInMillis(d.getTime());
    gc.set(GregorianCalendar.HOUR_OF_DAY, 23);
    gc.set(GregorianCalendar.MINUTE, 59);
    gc.set(GregorianCalendar.SECOND, 59);
    gc.set(GregorianCalendar.MILLISECOND, 0);
    return gc.getTimeInMillis();
}

From source file:op.tools.SYSCalendar.java

/**
 * nimmt das bergebene Datum und setzt die Uhrzeitkomponente auf 00:00:00.
 *
 * @param d/* w w w  .  j a v a 2 s. c  o m*/
 * @return das Ergebnis als TimeInMillis
 */
public static long startOfDay(Date d) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTimeInMillis(d.getTime());
    gc.set(GregorianCalendar.HOUR_OF_DAY, 0);
    gc.set(GregorianCalendar.MINUTE, 0);
    gc.set(GregorianCalendar.SECOND, 0);
    gc.set(GregorianCalendar.MILLISECOND, 0);
    return gc.getTimeInMillis();
}

From source file:op.tools.SYSCalendar.java

/**
 * Diese Routine vergleicht Uhrzeiten, die in zwei longs hinterlegt sind.
 * Das Besondere dabei ist, dass das Datum ausser acht gelassen wird.
 *
 * @return int < 0, wenn time1 < time2; int == 0, wenn time1 = time2; int > 0, wenn time1 > time2
 * @time1/*  ww  w  .j a v  a  2s  .  co  m*/
 * @time2
 */
public static int compareTime(long time1, long time2) {
    // normalisierung des timestamps
    GregorianCalendar gc1 = new GregorianCalendar();
    gc1.setTimeInMillis(time1);
    GregorianCalendar gc2 = new GregorianCalendar();
    gc2.setTimeInMillis(time2);
    gc2 = setDate2Time(gc1, gc2); // Hier werden die Daten gleichgesetzt.
    return gc1.compareTo(gc2);
}

From source file:org.n52.oxf.ui.swing.ChartDialog.java

/**
 * /*  ww  w .j av  a  2s  .  c  om*/
 */
public void actionPerformed(ActionEvent e) {
    try {
        if (e.getSource().equals(applyButton)) {
            paramCon.setParameterValue(Parameter.COMMON_NAME_TIME, timePeriodPanel.getChosenTime());

            OperationResult opRes = adapter.doOperation(
                    descriptor.getOperationsMetadata().getOperationByName(adapter.getResourceOperationName()),
                    paramCon);
            observations = featureStore.unmarshalFeatures(opRes);

            initChartPanel(observations, paramCon);
        }

        else if (e.getSource().equals(nowButton)) {
            GregorianCalendar calendar = new GregorianCalendar();
            calendar.setTimeInMillis(System.currentTimeMillis());
            Date date = calendar.getTime();

            SimpleDateFormat ISO8601FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
            String result = ISO8601FORMAT.format(date);
            //convert into YYYYMMDDTHH:mm:ss+HH:00
            //- note the added colon for the Timezone
            result = result.substring(0, result.length() - 2) + ":" + result.substring(result.length() - 2);

            ITimePosition endPos = new TimePosition(result);
            timePeriodPanel.setEndPosition(endPos);
        }
    } catch (Exception exc) {
        exc.printStackTrace();
    }
}

From source file:org.kuali.kfs.coa.batch.dataaccess.impl.AccountingPeriodFiscalYearMakerImpl.java

/**
 * Adds one year to the given date/*from  w  w  w. j  a  v a2 s .com*/
 * 
 * @param inDate date to increment
 * @return Date incoming date plus one year
 */
protected java.sql.Date addYearToDate(Date inDate) {
    GregorianCalendar currentCalendarDate = new GregorianCalendar();
    currentCalendarDate.clear();

    currentCalendarDate.setTimeInMillis(inDate.getTime());
    currentCalendarDate.add(GregorianCalendar.YEAR, 1);

    return new Date(currentCalendarDate.getTimeInMillis());
}

From source file:es.itecban.deployment.executionmanager.gui.swf.service.PlanLaunchManager.java

public ExecutionReportType getReportFromCodifiedPlanId(String planId) throws DatatypeConfigurationException {
    ExecutionReportType planReport = null;
    // the planId given is a concatenation of the name of the plan and the
    // startTime of the plan of the report
    String reportName = planId.substring(0, planId.lastIndexOf('|'));
    String calendarString = planId.substring(planId.lastIndexOf('|') + 1);
    long calendarMiliSecs = Long.decode(calendarString);
    GregorianCalendar gregCalendar = new GregorianCalendar();
    gregCalendar.setTimeInMillis(calendarMiliSecs);
    XMLGregorianCalendar xmlCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregCalendar);
    planReport = reportManager.findExecutionReportByPlanId(reportName, xmlCalendar);
    return planReport;
}

From source file:op.tools.SYSCalendar.java

/**
 * @param ts Ist ein TS mit der Uhrzeit, fr die wir wissen mchten in welchem Bereich der Medikamenten Vergabe
 *           sie liegt. Frh morgens, morgens... etc. Das Datum in diesem TS ist egal. Es geht NUR um die Uhrzeit.
 * @return Zeit-Konstante gem den Angaben in SYSConst.FM ... SYSConst.NA.
 *///w w w.j  av  a2  s.  c  o  m
public static byte ermittleZeit(long ts) {
    byte zeit;
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTimeInMillis(ts);
    long fm = parseTime(OPDE.getProps().getProperty("FM"), gc).getTimeInMillis();
    long mo = parseTime(OPDE.getProps().getProperty("MO"), gc).getTimeInMillis();
    long mi = parseTime(OPDE.getProps().getProperty("MI"), gc).getTimeInMillis();
    long nm = parseTime(OPDE.getProps().getProperty("NM"), gc).getTimeInMillis();
    long ab = parseTime(OPDE.getProps().getProperty("AB"), gc).getTimeInMillis();
    long na = parseTime(OPDE.getProps().getProperty("NA"), gc).getTimeInMillis();
    if (fm <= ts && ts < mo) {
        zeit = SYSConst.FM;
    } else if (mo <= ts && ts < mi) {
        zeit = SYSConst.MO;
    } else if (mi <= ts && ts < nm) {
        zeit = SYSConst.MI;
    } else if (nm <= ts && ts < ab) {
        zeit = SYSConst.NM;
    } else if (ab <= ts && ts < na) {
        zeit = SYSConst.AB;
    } else {
        zeit = SYSConst.NA;
    }
    return zeit;
}

From source file:org.betaconceptframework.astroboa.model.jaxb.adapter.BinaryChannelAdapter.java

@Override
public BinaryChannelType marshal(BinaryChannel binaryChannel) throws Exception {

    if (binaryChannel != null) {
        BinaryChannelType binaryChannelType = new BinaryChannelType();

        binaryChannelType.setEncoding(binaryChannel.getEncoding());
        binaryChannelType.setId(binaryChannel.getId());

        if (binaryChannel.getModified() != null) {
            GregorianCalendar gregCalendar = new GregorianCalendar(binaryChannel.getModified().getTimeZone());
            gregCalendar.setTimeInMillis(binaryChannel.getModified().getTimeInMillis());

            binaryChannelType.setLastModificationDate(df.newXMLGregorianCalendar(gregCalendar));
        }/*from w  w w . j av a2 s .  c o  m*/

        binaryChannelType.setMimeType(binaryChannel.getMimeType());
        binaryChannelType.setSourceFileName(binaryChannel.getSourceFilename());

        binaryChannelType.setUrl(binaryChannel.buildResourceApiURL(null, null, null, null, null, false, false));

        if (marshallBinaryContent) {
            byte[] content = binaryChannel.getContent();

            if (content != null) {
                //No need to encode since it is done automatically from JAXB
                //binaryChannelType.setContent(Base64.encodeBase64(content));
                binaryChannelType.setContent(content);
            }
        }

        return binaryChannelType;

    }

    return null;
}

From source file:eu.openanalytics.rsb.data.FileResultStore.java

private PersistedResult buildPersistedResult(final String applicationName, final String userName,
        final UUID jobId, final File resultFile) {
    final GregorianCalendar resultTime = (GregorianCalendar) GregorianCalendar.getInstance();
    resultTime.setTimeInMillis(resultFile.lastModified());

    final boolean success = !StringUtils.contains(resultFile.getName(), ERROR_FILE_INFIX_EXTENSION + ".");
    final MimeType mimeType = Util.getMimeType(resultFile);

    return new PersistedResult(applicationName, userName, jobId, resultTime, success, mimeType) {
        @Override//w  w  w.jav a 2 s . c  om
        public InputStream getData() {
            try {
                return new FileInputStream(resultFile);
            } catch (final FileNotFoundException fnfe) {
                throw new IllegalStateException(fnfe);
            }
        }

        @Override
        public long getDataLength() {
            return resultFile.length();
        }
    };
}

From source file:org.energyos.espi.datacustodian.web.api.ExportServiceTests.java

private GregorianCalendar getGregorianCalendar(int secondsFromEpoch) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTimeZone(TimeZone.getTimeZone("UTC"));
    cal.setTimeInMillis(secondsFromEpoch * 1000);
    return cal;/*from  w ww  . j  a v a2 s  .co m*/
}