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:TimePeriod.java

/**
 * Setzt den bis-Wert auf einen der Standard-Typen
 * //from  ww w.  j  a v  a  2s.c  o  m
 * @param neuertyp
 */
public void setToTyp(int neuertyp) {
    this.to_typ = neuertyp;
    if (from_typ != to_typ)
        typ = -1;
    else
        typ = neuertyp;
    switch (neuertyp) {
    case TODAY:
        to = new GregorianCalendar();
        set2359(to);
        break;
    case YESTERDAY:
        to = new GregorianCalendar();
        set2359(to);
        to.setTimeInMillis(to.getTimeInMillis() - ONE_DAY);
        break;
    case THIS_WEEK:
        to = new GregorianCalendar();
        int day_of_week = to.get(Calendar.DAY_OF_WEEK);
        // unsere Woche beginnt am Montag. Montag hat den Wert 2
        int day_offset_von;
        // wenn es sonntag ist, wird die zurck liegende woche betrachtet
        if (day_of_week == 1) {
            day_offset_von = -6;
        } else {
            day_offset_von = 2 - day_of_week;
        }
        // bis ist logischerweise 6-Tage nach von
        int day_offset_bis = day_offset_von + 6;
        set2359(to);
        to.setTimeInMillis(to.getTimeInMillis() + ONE_DAY * day_offset_bis);
        break;
    case LAST_WEEK:
        // wie diese woche, nur 7 tage weiter zurck
        to = new GregorianCalendar();
        int day_of_week2 = to.get(Calendar.DAY_OF_WEEK);
        // unsere Woche beginnt am Montag. Montag hat den Wert 2
        int day_offset_von2;
        // wenn es sonntag ist, wird die zurck liegende woche betrachtet
        if (day_of_week2 == 1) {
            day_offset_von2 = -13;
        } else {
            day_offset_von2 = -5 - day_of_week2;
        }
        // bis ist logischerweise 6-Tage nach von
        int day_offset_bis2 = day_offset_von2 + 6;
        set2359(to);
        to.setTimeInMillis(to.getTimeInMillis() + ONE_DAY * day_offset_bis2);
        break;
    case THIS_MONTH:
        GregorianCalendar temp = new GregorianCalendar();
        setMidnight(temp);
        temp.set(Calendar.DAY_OF_MONTH, 1);
        to = new GregorianCalendar();
        set2359(to);
        // wann der letzte tag im monat ist ist unklar, also solange weiter
        // gehen,
        // bis der neue monat anfngt, dann einen tag zurck
        while (to.get(Calendar.MONTH) == temp.get(Calendar.MONTH))
            to.setTimeInMillis(to.getTimeInMillis() + ONE_DAY);
        // Jetzt wieder einen tag zurck
        to.setTimeInMillis(to.getTimeInMillis() - ONE_DAY);
        break;
    case LAST_MONTH:
        GregorianCalendar temp2 = new GregorianCalendar();
        setMidnight(temp2);
        temp2.set(Calendar.DAY_OF_MONTH, 1);
        // der erste tag des letzten Monats ist vielleicht nicht mehr in
        // diesem Jahr, also
        // rckwrts laufen, bis wieder ein erster Tag gefunden wird
        temp2.setTimeInMillis(temp2.getTimeInMillis() - ONE_DAY);
        to = new GregorianCalendar();
        to.setTimeInMillis(temp2.getTimeInMillis());
        set2359(to);
        break;
    case THIS_JEAR:
        to = new GregorianCalendar();
        set2359(to);
        to.set(Calendar.MONTH, 11);
        to.set(Calendar.DAY_OF_MONTH, 31);
        break;
    case LAST_JEAR:
        to = new GregorianCalendar();
        int jahr = to.get(Calendar.YEAR);
        jahr--;
        set2359(to);
        to.set(Calendar.MONTH, 11);
        to.set(Calendar.DAY_OF_MONTH, 31);
        to.set(Calendar.YEAR, jahr);
        break;
    case EVER:
        to = new GregorianCalendar();
        int jahr2 = to.get(Calendar.YEAR);
        set2359(to);
        to.set(Calendar.MONTH, 11);
        to.set(Calendar.DAY_OF_MONTH, 31);
        to.set(Calendar.YEAR, jahr2);
        break;
    }
    // Von darf nicht nach bis liegen, ist bis schon initialisiert, so muss
    // es angepasst werden
    if (from != null)
        if (to.before(from)) {
            from.setTimeInMillis(to.getTimeInMillis());
            setMidnight(from);
            from_typ = to_typ;
        }
}

From source file:com.opendesign.utils.Day.java

private void createDateFactorsByGivenMilliSecond(long milliSeconds, TimeZone timeZone) {
    if (timeZone == null) {
        this.timeZone = TimeZone.getDefault();
    } else {/*from w  w w. j  ava2s.c o m*/
        this.timeZone = timeZone;
    }

    GregorianCalendar todaysDate = new GregorianCalendar(this.timeZone);

    if (milliSeconds != 0) {
        todaysDate.setTimeInMillis(milliSeconds);
    }

    this.year = todaysDate.get(Calendar.YEAR);
    this.month = todaysDate.get(Calendar.MONTH) + 1;
    this.day = todaysDate.get(Calendar.DAY_OF_MONTH);
    this.hour = todaysDate.get(Calendar.HOUR_OF_DAY);
    this.minute = todaysDate.get(Calendar.MINUTE);
    this.second = todaysDate.get(Calendar.SECOND);
}

From source file:org.betaconceptframework.astroboa.model.jaxb.visitor.ContentObjectMarshalVisitor.java

protected <T> void marshallValueForSimpleProperty(SimpleCmsPropertyDefinition<T> simplePropertyDefinition,
        CmsPropertyInfo simpleCmsProperty, Object value) {

    if (value != null) {

        switch (simplePropertyDefinition.getValueType()) {
        case String:
        case Boolean:
        case Double:
        case Long:
        case Date:

            final SimpleCmsPropertyType simpleCmsPropertyType = new SimpleCmsPropertyType();

            simpleCmsPropertyType.setExportAsAnAttribute(
                    ((SimpleCmsPropertyDefinitionImpl) simplePropertyDefinition).isRepresentsAnXmlAttribute());

            if (marshalOutputTypeIsJSON() && simplePropertyDefinition.isMultiple()) {
                simpleCmsPropertyType.setExportAsAnArray(true);
            }//ww  w  . j  av a  2s  . c o  m

            CmsPropertyTypeJAXBElement<SimpleCmsPropertyType> simpleCmsPropertyTypeJaxbElement = new CmsPropertyTypeJAXBElement(
                    new QName(simplePropertyDefinition.getQualifiedName().getLocalPart()),
                    SimpleCmsPropertyType.class, null, simpleCmsPropertyType);

            if (value instanceof String) {
                simpleCmsPropertyTypeJaxbElement.getValue().setContent((String) value);
            } else if (value instanceof Boolean) {
                simpleCmsPropertyTypeJaxbElement.getValue().setContent(((Boolean) value).toString());
            } else if (value instanceof Double) {
                simpleCmsPropertyTypeJaxbElement.getValue().setContent(((Double) value).toString());
            } else if (value instanceof Long) {
                simpleCmsPropertyTypeJaxbElement.getValue().setContent(((Long) value).toString());
            } else if (value instanceof Calendar) {
                Calendar calendar = (Calendar) value;

                try {
                    if (((CalendarPropertyDefinition) simplePropertyDefinition).isDateTime()) {
                        GregorianCalendar gregCalendar = new GregorianCalendar(calendar.getTimeZone());
                        gregCalendar.setTimeInMillis(calendar.getTimeInMillis());

                        simpleCmsPropertyTypeJaxbElement.getValue()
                                .setContent(df.newXMLGregorianCalendar(gregCalendar).toXMLFormat());
                    } else {
                        simpleCmsPropertyTypeJaxbElement.getValue()
                                .setContent(df.newXMLGregorianCalendarDate(calendar.get(Calendar.YEAR),
                                        calendar.get(Calendar.MONTH) + 1, // Calendar.MONTH is zero based, XSD Date datatype's month field starts
                                        //   with JANUARY as 1.
                                        calendar.get(Calendar.DAY_OF_MONTH), DatatypeConstants.FIELD_UNDEFINED)
                                        .toXMLFormat());
                    }
                } catch (Exception e) {
                    throw new CmsException("Property " + simpleCmsProperty.getFullPath() + " Calendar value "
                            + DateUtils.format(calendar), e);
                }
            } else {
                throw new CmsException("Property " + simpleCmsProperty.getFullPath() + " has value type "
                        + simplePropertyDefinition.getValueType() + " but contains value of type "
                        + value.getClass().getName());
            }

            addJaxbElementToCurrentParentComplexCmsPropertyType(simpleCmsPropertyTypeJaxbElement);

            break;
        case TopicReference:

            try {
                TopicType topicType = marshalTopicReference(value);

                if (marshalOutputTypeIsJSON() && simplePropertyDefinition.isMultiple()) {
                    topicType.setExportAsAnArray(true);
                }

                CmsPropertyTypeJAXBElement<TopicType> topicTypeJaxbElement = new CmsPropertyTypeJAXBElement(
                        new QName(simplePropertyDefinition.getQualifiedName().getLocalPart()), TopicType.class,
                        null, topicType);

                addJaxbElementToCurrentParentComplexCmsPropertyType(topicTypeJaxbElement);

            } catch (Exception e) {
                throw new CmsException("Unable to marshal topic " + ((Topic) value).getName(), e);
            }

            break;
        case Binary:
            try {
                BinaryChannelType binaryChannelType = getBinaryChannelAdapter().marshal((BinaryChannel) value);

                if (marshalOutputTypeIsJSON() && simplePropertyDefinition.isMultiple()) {
                    binaryChannelType.setExportAsAnArray(true);
                }

                CmsPropertyTypeJAXBElement<BinaryChannelType> binaryChannelTypeJaxbElement = new CmsPropertyTypeJAXBElement(
                        new QName(simplePropertyDefinition.getQualifiedName().getLocalPart()),
                        BinaryChannelType.class, null, binaryChannelType);

                addJaxbElementToCurrentParentComplexCmsPropertyType(binaryChannelTypeJaxbElement);

            } catch (Exception e) {
                throw new CmsException("Unable to marshal binary channel " + ((BinaryChannel) value).getName(),
                        e);
            }

            break;
        case ObjectReference:
            try {

                logger.debug("\t Property is a reference to another object");

                Marshaller objectReferenceMarshaller = CmsEntitySerialization.Context
                        .createMarshaller(marshalOutputTypeIsJSON() ? ResourceRepresentationType.JSON
                                : ResourceRepresentationType.XML, prettyPrintIsEnabled());

                //For now only porifle.title is provided. 
                objectReferenceMarshaller.setProperty(AstroboaMarshaller.CMS_PROPERTIES_TO_BE_MARSHALLED,
                        Arrays.asList("profile.title"));

                ContentObjectAdapter adapter = new ContentObjectAdapter();
                adapter.setMarshaller(objectReferenceMarshaller, marshallBinaryContent, false);
                objectReferenceMarshaller.setAdapter(adapter);

                ContentObjectType contentObjectType = objectReferenceMarshaller
                        .getAdapter(ContentObjectAdapter.class).marshal((ContentObject) value);

                if (marshalOutputTypeIsJSON() && simplePropertyDefinition.isMultiple()) {
                    contentObjectType.setExportAsAnArray(true);
                }

                CmsPropertyTypeJAXBElement<ContentObjectType> contentObjectReferenceTypeJaxbElement = new CmsPropertyTypeJAXBElement(
                        new QName(simplePropertyDefinition.getQualifiedName().getLocalPart()),
                        ContentObjectType.class, null, contentObjectType);

                addJaxbElementToCurrentParentComplexCmsPropertyType(contentObjectReferenceTypeJaxbElement);

            } catch (Exception e) {
                throw new CmsException("Unable to marshal contentObject " + ((ContentObject) value).getId(), e);
            }

            break;
        default:
            break;
        }

    }
}

From source file:com.openkm.cmis.CmisRepository.java

/**
 * Converts milliseconds into a calendar object.
 *///from  w  ww . j a v a2  s.co m
private static GregorianCalendar millisToCalendar(long millis) {
    GregorianCalendar result = new GregorianCalendar();
    result.setTimeZone(TimeZone.getTimeZone("GMT"));
    result.setTimeInMillis((long) (Math.ceil((double) millis / 1000) * 1000));

    return result;
}

From source file:com.forrestguice.suntimeswidget.SuntimesUtils.java

@SuppressWarnings("ConstantConditions")
public TimeDisplayText timeDeltaLongDisplayString(long timeSpan1, long timeSpan2, boolean showSeconds) {
    String value = strSpace;//from  ww w  . j  a  v  a2  s .  c  o m
    String units = strEmpty;
    String suffix = strEmpty;

    long timeSpan = timeSpan2 - timeSpan1;
    GregorianCalendar d = new GregorianCalendar();
    d.setTimeInMillis(timeSpan);
    long timeInMillis = d.getTimeInMillis();

    long numberOfSeconds = timeInMillis / 1000;
    suffix += ((numberOfSeconds > 0) ? strTimeLonger : strTimeShorter);
    numberOfSeconds = Math.abs(numberOfSeconds);

    long numberOfMinutes = numberOfSeconds / 60;
    long numberOfHours = numberOfMinutes / 60;
    long numberOfDays = numberOfHours / 24;
    long numberOfWeeks = numberOfDays / 7;
    long numberOfYears = numberOfDays / 365;

    long remainingWeeks = (long) (numberOfWeeks % 52.1429);
    long remainingDays = numberOfDays % 7;
    //long remainingDays = numberOfDays % 365;
    long remainingHours = numberOfHours % 24;
    long remainingMinutes = numberOfMinutes % 60;
    long remainingSeconds = numberOfSeconds % 60;

    boolean showingYears = (numberOfYears > 0);
    if (showingYears)
        value += String.format(strTimeDeltaFormat, numberOfYears, strYears);

    boolean showingWeeks = (numberOfWeeks > 0);
    if (showingWeeks)
        value += (showingYears ? strSpace : strEmpty)
                + String.format(strTimeDeltaFormat, remainingWeeks, strWeeks);

    boolean showingDays = (remainingDays > 0);
    if (showingDays)
        value += (showingYears || showingWeeks ? strSpace : strEmpty)
                + String.format(strTimeDeltaFormat, remainingDays, strDays);

    boolean showingHours = (!showingYears && !showingWeeks && remainingHours > 0);
    if (showingHours)
        value += (showingYears || showingWeeks || showingDays ? strSpace : strEmpty)
                + String.format(strTimeDeltaFormat, remainingHours, strHours);

    boolean showingMinutes = (!showingDays && !showingWeeks && !showingYears && remainingMinutes > 0);
    if (showingMinutes)
        value += (showingYears || showingWeeks || showingDays || showingHours ? strSpace : strEmpty)
                + String.format(strTimeDeltaFormat, remainingMinutes, strMinutes);

    boolean showingSeconds = (showSeconds && !showingDays && !showingWeeks && !showingYears
            && (remainingSeconds > 0));
    if (showingSeconds)
        value += (showingHours || showingMinutes ? strSpace : strEmpty)
                + String.format(strTimeDeltaFormat, remainingSeconds, strSeconds);

    if (!showingSeconds && !showingMinutes && !showingHours && !showingDays && !showingWeeks && !showingYears) {
        if (showSeconds)
            value += String.format(strTimeDeltaFormat, "0", strSeconds);
        else
            value += String.format(strTimeDeltaFormat, "1", strMinutes);
    }

    TimeDisplayText text = new TimeDisplayText(value.trim(), units, suffix);
    text.setRawValue(timeSpan);
    return text;
}

From source file:org.eevolution.form.VSCRP.java

public CategoryDataset createWeightDataset(Timestamp start, MResource r) {

    GregorianCalendar gc1 = new GregorianCalendar();
    gc1.setTimeInMillis(start.getTime());
    gc1.clear(Calendar.MILLISECOND);
    gc1.clear(Calendar.SECOND);/*  w  w  w.j av a  2 s .c  om*/
    gc1.clear(Calendar.MINUTE);
    gc1.clear(Calendar.HOUR_OF_DAY);

    String namecapacity = Msg.translate(Env.getCtx(), "Capacity");
    String nameload = Msg.translate(Env.getCtx(), "Load");
    String namesummary = Msg.translate(Env.getCtx(), "Summary");
    String namepossiblecapacity = "Possible Capacity";

    MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null);

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    double currentweight = DB.getSQLValue(null,
            "Select SUM( (mo.qtyordered-mo.qtydelivered)*(Select mp.weight From m_product mp Where mo.m_product_id=mp.m_product_id )  )From mpc_order mo Where ad_client_id=?",
            r.getAD_Client_ID());
    // fjviejo e-evolution machineqty capacidad por el numero de maquinas
    // double dailyCapacity = DB.getSQLValue(null,"Select dailycapacity From s_resource Where s_resource_id=?",r.getS_Resource_ID());
    double dailyCapacity = DB.getSQLValue(null,
            "Select dailycapacity*MachineQty From s_resource Where s_resource_id=?", r.getS_Resource_ID());
    System.out.println("***** Capacidad diaria " + dailyCapacity);
    // e-evolution end
    double utilization = DB.getSQLValue(null,
            "Select percentutillization From s_resource Where s_resource_id=?", r.getS_Resource_ID());

    double summary = 0;

    int day = 0;
    while (day < 32) {

        day++;

        switch (gc1.get(Calendar.DAY_OF_WEEK)) {

        case Calendar.SUNDAY:

            if (t.isOnSunday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.MONDAY:

            if (t.isOnMonday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.TUESDAY:

            if (t.isOnTuesday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.WEDNESDAY:

            if (t.isOnWednesday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.THURSDAY:

            if (t.isOnThursday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.FRIDAY:

            if (t.isOnFriday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.SATURDAY:

            if (t.isOnSaturday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;
        }

        dataset.addValue(currentweight, nameload, new Integer(day));
        dataset.addValue(summary, namesummary, new Integer(day));

        gc1.add(Calendar.DATE, 1);
    }

    return dataset;
}

From source file:org.betaconceptframework.astroboa.test.engine.AbstractRepositoryTest.java

protected String convertCalendarToXMLFormat(Calendar calendar, boolean dateTimePattern) {
     if (dateTimePattern) {
         GregorianCalendar gregCalendar = new GregorianCalendar(calendar.getTimeZone());
         gregCalendar.setTimeInMillis(calendar.getTimeInMillis());

         return df.newXMLGregorianCalendar(gregCalendar).toXMLFormat();
     } else {//from ww w.  jav  a2 s  . c  om
         return df.newXMLGregorianCalendarDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, // Calendar.MONTH is zero based, XSD Date datatype's month field starts
                 //   with JANUARY as 1.
                 calendar.get(Calendar.DAY_OF_MONTH), DatatypeConstants.FIELD_UNDEFINED).toXMLFormat();
     }
 }

From source file:org.eevolution.form.VCRP.java

public boolean checkResourceTypeAvailability(Timestamp dateTime, MResourceType t) {

    if (!t.isDateSlot()) {

        return true;
    }/* w  w w.jav a2  s.  c om*/

    GregorianCalendar gc = new GregorianCalendar();
    gc.setTimeInMillis(dateTime.getTime());

    boolean retValue = false;
    switch (gc.get(Calendar.DAY_OF_WEEK)) {

    case Calendar.SUNDAY:
        retValue = t.isOnSunday();
        break;

    case Calendar.MONDAY:
        retValue = t.isOnMonday();
        break;

    case Calendar.TUESDAY:
        retValue = t.isOnTuesday();
        break;

    case Calendar.WEDNESDAY:
        retValue = t.isOnWednesday();
        break;

    case Calendar.THURSDAY:
        retValue = t.isOnThursday();
        break;

    case Calendar.FRIDAY:
        retValue = t.isOnFriday();
        break;

    case Calendar.SATURDAY:
        retValue = t.isOnSaturday();
        break;
    }

    return retValue;
}

From source file:eu.tango.energymodeller.datasourceclient.SlurmDataSourceAdaptor.java

@Override
public List<ApplicationOnHost> getHostApplicationList(JOB_STATUS state) {
    ArrayList<ApplicationOnHost> answer = new ArrayList<>();

    /**/*ww  w .ja v a 2  s  .  c o m*/
     * squeue has various jobs states that are possible: see:
     * https://slurm.schedmd.com/squeue.html
     *
     * namely: PENDING (PD), RUNNING (R), SUSPENDED (S), STOPPED (ST),
     * COMPLETING (CG), COMPLETED (CD), CONFIGURING (CF), CANCELLED (CA),
     * FAILED (F), TIMEOUT (TO), PREEMPTED (PR), BOOT_FAIL (BF) , NODE_FAIL
     * (NF), REVOKED (RV), and SPECIAL_EXIT (SE)
     */
    String jobState;
    if (state == null) {
        jobState = "";
    } else {
        jobState = "-t " + state.name();
    }

    /*
     * This queries what jobs are currently running, it outputs
     * "JOBID, NAME, TIME, NODELIST (REASON)"
     * "JOBID, JOB_NAME, USER, STATUS, TIME, MAX_TIME, NODELIST (REASON)"
     * One line per job and space separated.
     * 
     * squeue -t RUNNING -l | awk 'NR> 1 {split($0,values,"[ \t\n]+"); 
     * printf values[1] " " ; printf values[2] " "; printf values[4] " "; 
     * printf values[5] " "; printf values[6] " "; printf values[7] " " ; 
     * printf values[8] " "; print values[10]}'
     *
     * The output looks like:
     * 
     * 3009 RK-BENCH Kavanagr RUNNING 8:06 ns52
     *        
     */
    String maincmd = "squeue " + jobState + " -l | awk 'NR> 2 {split($0,values,\"[ \\t\\n]+\"); "
            + "printf values[1] \" \"; " + "printf values[2] \" \"; " + "printf values[4] \" \"; "
            + "printf values[5] \" \"; " + "printf values[6] \" \"; " + "printf values[7] \" \"; "
            + "printf values[8] \" \"; " + "print values[10]}'";
    ArrayList<String> output = execCmd(maincmd);
    for (String line : output) { //Each line represents a different application
        if (line != null && !line.isEmpty()) {
            line = line.trim();
            String[] items = line.split(" ");
            try {
                int appId = Integer.parseInt(items[0]);
                String name = items[1];
                String status = items[3];
                long runningTime = parseDurationString(items[4]); //units seconds
                long maxRuntime = parseDurationString(items[5]); //units seconds
                long currentTime = System.currentTimeMillis(); //units milliseconds
                long startTime = currentTime - TimeUnit.SECONDS.toMillis(runningTime); //unit milliseconds
                GregorianCalendar start = new GregorianCalendar();
                GregorianCalendar deadline = null;
                start.setTimeInMillis(startTime);
                if (maxRuntime != 0) {
                    deadline = new GregorianCalendar();
                    deadline.setTimeInMillis(startTime + TimeUnit.SECONDS.toMillis(maxRuntime));
                }
                ArrayList<String> hostStrings = getHostList(items[6]);
                for (String hostStr : hostStrings) {
                    Host host = getHostByName(hostStr);
                    ApplicationOnHost app = new ApplicationOnHost(appId, name, host);
                    app.setCreated(start);
                    app.setDeadline(deadline);
                    if (state != null) {
                        app.setStatus(state);
                    } else {
                        app.setStatus(status);
                    }
                    answer.add(app);
                }
            } catch (NumberFormatException ex) {
                Logger.getLogger(SlurmDataSourceAdaptor.class.getName()).log(Level.SEVERE,
                        "Unexpected number format", ex);
            }
        }
    }
    return answer;
}

From source file:edu.harvard.i2b2.pm.dao.PMDbDao.java

public static XMLGregorianCalendar long2Gregorian(long date) {
    DatatypeFactory dataTypeFactory;
    try {/*from   w  w w .  j a va 2s. com*/
        dataTypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException(e);
    }
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTimeInMillis(date);
    return dataTypeFactory.newXMLGregorianCalendar(gc);
}