Example usage for java.text DateFormat format

List of usage examples for java.text DateFormat format

Introduction

In this page you can find the example usage for java.text DateFormat format.

Prototype

public final String format(Date date) 

Source Link

Document

Formats a Date into a date-time string.

Usage

From source file:org.linkedeconomy.espa.service.impl.rdf.ReviewEspaImpl.java

public static void review() throws ParseException {

    //services for each table
    ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
    ReviewService rev = (ReviewService) ctx.getBean("reviewServiceImpl");

    List<Review> review = rev.getReview();

    //--------------RDF Model--------------//
    Model model = ModelFactory.createDefaultModel();
    Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
    InfModel infModel = ModelFactory.createInfModel(reasoner, model);

    model.setNsPrefix("elod", OntologySpecification.elodPrefix);
    model.setNsPrefix("gr", OntologySpecification.goodRelationsPrefix);
    model.setNsPrefix("dcterms", OntologySpecification.dctermsPrefix);

    //number format
    DecimalFormat df = new DecimalFormat("0.00");

    for (Review review1 : review) {

        Resource instanceCurrency = infModel.createResource("http://linkedeconomy.org/resource/Currency/EUR");
        Resource instanceCountry = infModel.createResource("http://linkedeconomy.org/resource/Country/GR");
        Resource instanceBudgetUps = infModel.createResource(
                OntologySpecification.instancePrefix + "UnitPriceSpecification/BudgetItem/" + review1.getOps());
        Resource instanceSpendingUps = infModel.createResource(OntologySpecification.instancePrefix
                + "UnitPriceSpecification/SpendingItem/" + review1.getOps());
        Resource instanceBudget = infModel
                .createResource(OntologySpecification.instancePrefix + "BudgetItem/" + review1.getOps());
        Resource instanceSpending = infModel
                .createResource(OntologySpecification.instancePrefix + "SpendingItem/" + review1.getOps());
        Resource instanceSpendingExpLine = infModel.createResource(
                OntologySpecification.instancePrefix + "ExpenditureLine/SpendingItem/" + review1.getOps());
        Resource instanceProject = infModel
                .createResource(OntologySpecification.instancePrefix + "Subsidy/" + review1.getOps());
        DateFormat dfDate = new SimpleDateFormat("dd/MM/yyyy");
        DateFormat dfDate2 = new SimpleDateFormat("yyyy-MM-dd");
        DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        java.util.Date stDateStarts;
        java.util.Date stDateEnds;
        java.util.Date stDateIssued;
        stDateStarts = dfDate.parse(review1.getStartDate());
        stDateEnds = dfDate.parse(review1.getFinishDate());
        stDateIssued = dfDate2.parse(review1.getDate().toString());
        String startDate = df2.format(stDateStarts);
        String endDate = df2.format(stDateEnds);
        String issuedDate = df2.format(stDateIssued);

        infModel.add(instanceBudgetUps, RDF.type, OntologySpecification.priceSpecificationResource);
        infModel.add(instanceSpendingUps, RDF.type, OntologySpecification.priceSpecificationResource);
        infModel.add(instanceBudget, RDF.type, OntologySpecification.budgetResource);
        infModel.add(instanceSpending, RDF.type, OntologySpecification.spendingResource);
        infModel.add(instanceSpendingExpLine, RDF.type, OntologySpecification.expLineResource);
        infModel.add(instanceProject, RDF.type, OntologySpecification.subsidyResource);
        instanceProject.addProperty(OntologySpecification.hasRelatedBudgetItem, instanceBudget);
        model.add(OntologySpecification.subsidyResource, RDFS.subClassOf,
                OntologySpecification.projectResource);
        model.add(OntologySpecification.budgetResource, RDFS.subClassOf,
                OntologySpecification.financialResource);
        model.add(OntologySpecification.spendingResource, RDFS.subClassOf,
                OntologySpecification.financialResource);
        instanceProject.addProperty(OntologySpecification.hasRelatedSpendingItem, instanceSpending);
        instanceProject.addProperty(OntologySpecification.countryIsoCode, instanceCountry);
        //            instanceBudget.addProperty(OntologySpecification.hasExpenditureLine, instanceBudgetExpLine);
        instanceSpending.addProperty(OntologySpecification.hasExpenditureLine, instanceSpendingExpLine);
        instanceBudget.addProperty(OntologySpecification.price, instanceBudgetUps);
        instanceSpendingExpLine.addProperty(OntologySpecification.amount, instanceSpendingUps);
        instanceSpendingUps.addProperty(OntologySpecification.hasCurrencyValue,
                df.format(review1.getSpending()), XSDDatatype.XSDfloat);
        instanceSpendingUps.addProperty(OntologySpecification.valueAddedTaxIncluded, "true",
                XSDDatatype.XSDboolean);
        instanceSpendingUps.addProperty(OntologySpecification.hasCurrency, instanceCurrency);
        instanceBudgetUps.addProperty(OntologySpecification.hasCurrency, instanceCurrency);
        instanceBudgetUps.addProperty(OntologySpecification.hasCurrencyValue, df.format(review1.getBudget()),
                XSDDatatype.XSDfloat);/*  w  w  w. ja  va2  s .com*/
        instanceBudgetUps.addProperty(OntologySpecification.valueAddedTaxIncluded, "true",
                XSDDatatype.XSDboolean);
        instanceProject.addProperty(OntologySpecification.desc, String.valueOf(review1.getDescription()), "el");
        instanceProject.addProperty(OntologySpecification.title, String.valueOf(review1.getTitle()), "el");
        instanceProject.addProperty(OntologySpecification.projectId, String.valueOf(review1.getOps()),
                XSDDatatype.XSDstring);
        instanceProject.addProperty(OntologySpecification.issued, issuedDate, XSDDatatype.XSDdateTime);
        instanceProject.addProperty(OntologySpecification.completion, String.valueOf(review1.getCompletion()),
                XSDDatatype.XSDfloat);
        instanceProject.addProperty(OntologySpecification.countOfRelatedProjects,
                String.valueOf(review1.getSubProjects()), XSDDatatype.XSDstring);
        instanceProject.addProperty(OntologySpecification.startDate, startDate, XSDDatatype.XSDdateTime);
        instanceProject.addProperty(OntologySpecification.endDate, endDate, XSDDatatype.XSDdateTime);
    }

    try {
        FileOutputStream fout = new FileOutputStream(
                "/Users/giovaf/Documents/yds_pilot1/espa_tests/22-02-2016_ouput/reviewEspa.rdf");
        model.write(fout);
    } catch (IOException e) {
        System.out.println("Exception caught" + e.getMessage());
    }
}

From source file:foam.zizim.android.Util.java

public static void findDeletedIncidents(Context context) {

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date date = new java.util.Date();
    date.setYear(date.getYear() - 1);/*from ww  w. j  a va  2  s  . c  o  m*/
    StringBuilder datetime = new StringBuilder(dateFormat.format(date));
    String sinceDate = datetime.toString();
    //request all deleted incidents from the last year

    try {
        if (Incidents.getDeletedIncidentsFromWeb(sinceDate)) {
            List<IncidentsData> deletedIncidents = HandleXml
                    .processIncidentsXml(BoskoiService.incidentsResponse, context);
            BoskoiApplication.mDb.deleteIncidents(deletedIncidents);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.arm.connector.bridge.core.Utils.java

public static String dateToString(java.util.Date date, String format) {
    if (date != null) {
        DateFormat df = new SimpleDateFormat(format);
        return df.format(date);
    } else {/*from  w w w  .  ja  va 2  s .  c  o  m*/
        return "[no date]";
    }
}

From source file:com.mmone.gpdati.allotment.reader.AvailCrud.java

private static int modifyAllotment(XmlRpcClient client, java.util.Date dateStart, java.util.Date dateEnd,
        String action, int availability, int reservation, Integer invCode, Integer hotelCode) {

    Vector parameters = new Vector();
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

    parameters.add(new Integer(hotelCode)); //1
    parameters.add(new Integer(invCode)); //2
    //todo gestire con inventario unico -1
    int rate = 1; ///fisso nr da verificare per iu
    parameters.add(new Integer(rate)); //3 offerta
    parameters.add(new Integer(availability)); //4 disponibilit
    parameters.add(new Integer(reservation)); //5 prenotazione
    parameters.add(action); //6  Azione : set,increase,decrease
    parameters.add(df.format(dateStart).toString()); //7
    parameters.add(df.format(dateEnd).toString()); //8
    Vector result = new Vector();
    int ret = XRPC_SET_ALLOTMENT_RESULT_ERROR;

    String logData = "hotelCode=" + hotelCode + " - invCode=" + invCode + " - offerta=" + rate
            + " - availability=" + availability + " - reservation=" + reservation + " - action=" + action
            + " - dateStart=" + df.format(dateStart).toString() + " - dateEnd=" + df.format(dateEnd).toString()

    ;/*from   w ww  .  j a v  a 2 s  .c  o m*/
    Logger.getLogger("AvailCrud").log(Level.INFO, logData);

    try {
        result = (Vector) client.execute("backend.modifyAllotment", parameters);

    } catch (Exception e) {
        Logger.getLogger("AvailCrud").log(Level.SEVERE, "", e);
        // addError(ResponseBuilder.EWT_UNKNOWN, ResponseBuilder.ERR_SYSTEM_ERROR, "Error on updating  allotment (modifyAllotment)");
        return ret;
    }

    try {
        Map hret = (Map) result.get(0);
        ret = new Integer((String) hret.get("unique_allotment_service_response"));

    } catch (Exception e) {

    }

    Map hret = (Map) result.get(0);
    ret = new Integer((String) hret.get("unique_allotment_service_response"));
    Logger.getLogger("AvailCrud").log(Level.INFO, "Xrpc done ");

    return ret;
}

From source file:at.bitfire.davdroid.DateUtils.java

/**
 * Concatenates, if necessary, multiple RDATE/EXDATE lists and converts them to
 * a formatted string which Android calendar provider can process.
 * Android expects this format: "[TZID;]date1,date2,date3" where date is "yyyymmddThhmmss" (when
 * TZID is given) or "yyyymmddThhmmssZ". We don't use the TZID format here because then we're limited
 * to one time-zone, while an iCalendar may contain multiple EXDATE/RDATE lines with different time zones.
 * @param dates      one more more lists of RDATE or EXDATE
 * @param allDay    indicates whether the event is an all-day event or not
 * @return         formatted string for Android calendar provider:
 *                  - in case of all-day events, all dates/times are returned as yyyymmddT000000Z
 *                  - in case of timed events, all dates/times are returned as UTC time: yyyymmddThhmmssZ
 *///  w w  w.  j a  v  a 2 s.com
public static String recurrenceSetsToAndroidString(List<? extends DateListProperty> dates, boolean allDay)
        throws ParseException {
    List<String> strDates = new LinkedList<>();

    /*        rdate/exdate: DATE                                DATE_TIME
        all-day             store as ...T000000Z                cut off time and store as ...T000000Z
        event with time     (ignored)                           store as ...ThhmmssZ
    */
    final DateFormat dateFormatUtcMidnight = new SimpleDateFormat("yyyyMMdd'T'000000'Z'");

    for (DateListProperty dateListProp : dates) {
        final Value type = dateListProp.getDates().getType();

        if (Value.DATE_TIME.equals(type)) { // DATE-TIME values will be stored in UTC format for Android
            if (allDay) {
                DateList dateList = dateListProp.getDates();
                for (Date date : dateList)
                    strDates.add(dateFormatUtcMidnight.format(date));
            } else {
                dateListProp.setUtc(true);
                strDates.add(dateListProp.getValue());
            }

        } else if (Value.DATE.equals(type)) // DATE values have to be converted to DATE-TIME <date>T000000Z for Android
            for (Date date : dateListProp.getDates())
                strDates.add(dateFormatUtcMidnight.format(date));
    }
    return StringUtils.join(strDates, ",");
}

From source file:it.isislab.dmason.util.SystemManagement.Worker.thrower.DMasonWorkerWithGui.java

public static DMasonWorkerWithGui newInstance(String args[]) {
    RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();

    ////w w w .j  a  va 2s  .c om
    // Get name representing the running Java virtual machine.
    // It returns something like 6460@AURORA. Where the value
    // before the @ symbol is the PID.
    //
    String jvmName = bean.getName();

    //Used for log4j properties
    System.setProperty("logfile.name", "worker" + jvmName);

    //Used for log4j properties
    System.setProperty("steplog.name", "workerStep" + jvmName);

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss_SS");
    Date date = new Date();
    dateFormat.format(date);

    System.setProperty("timestamp", date.toLocaleString());

    System.setProperty("paramsfile.name", "params");
    try {
        File logPath = new File("Logs/workers");
        if (logPath.exists())
            FileUtils.cleanDirectory(logPath);
    } catch (IOException e) {
        //not a problem
    }

    logger = Logger.getLogger(DMasonWorker.class.getCanonicalName());
    logger.debug("StartWorker " + VERSION);

    autoStart = false;

    String ip = null;
    String port = null;
    String topic = "";
    updated = false;
    isBatch = false;
    topicPrefix = "";

    // ip, post, autoconnect
    if (args.length == 3) {
        ip = args[0];
        port = args[1];
        if (args[2].equals("autoconnect")) {
            autoStart = true;
        }
    }
    // ip, post, topic, event 
    if (args.length == 4) {
        autoStart = true;
        if (args[3].equals("update")) {
            updated = true;
        }
        if (args[3].equals("reset")) {
            updated = false;
            isBatch = false;
        }
        if (args[3].contains("Batch")) {
            updated = false;
            isBatch = true;
            topicPrefix = args[3];
        }
        ip = args[0];
        port = args[1];
        topic = args[2];
    }

    /*if(args.length == 2 && args[0].equals("auto"))
    {   autoStart = true;
       updated = true;
       topic = args[1];
    }
    if(args.length == 1 && args[0].equals("auto"))
    {   autoStart = true;
    }*/
    return new DMasonWorkerWithGui(autoStart, updated, isBatch, topic, ip, port);
}

From source file:com.facultyshowcase.app.ui.UIUtil.java

public static void writeProperty(EntityUtilWriter writer, String htmlClass, String label, Date date) {
    final DateFormat parser = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

    writeContainerBeginning(writer, htmlClass);

    writeLabel(writer, htmlClass, label);

    writer.append("<span ");
    writer.appendEscapedAttribute(CLASS, CmsHTMLClassNames.convertClassName(PROP + " " + htmlClass));
    writer.append(">");
    writer.appendEscapedData(date != null ? parser.format(date) : StringUtils.EMPTY);
    writer.append("</span>");

    writeContainerEnd(writer);/*from   ww  w  .j  av a  2 s  .c o  m*/
}

From source file:com.sun.socialsite.util.DateUtil.java

/**
 * Returns a string the represents the passed-in date parsed
 * according to the passed-in format.  Returns an empty string
 * if the date or the format is null./* w  ww  .jav a2  s. co m*/
 **/
public static String format(Date aDate, DateFormat aFormat) {
    if (aDate == null || aFormat == null) {
        return "";
    }
    synchronized (aFormat) {
        return aFormat.format(aDate);
    }
}

From source file:com.alcatel_lucent.nz.wnmsextract.reader.FileUtilities.java

public static String calendarToString(Calendar cal) {
    DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
    return (dateFormat.format(cal.getTime()));
}

From source file:com.wandrell.example.swss.test.util.factory.SecureSoapMessages.java

/**
 * Generates the current date in the format expected by the SOAP message.
 *
 * @return the current date//from  ww w  . j  a  va2s  .co  m
 */
private static final String getCurrentDate() {
    final DateFormat format; // Format to apply

    // Zulu time format
    format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    format.setTimeZone(TimeZone.getTimeZone("UTC"));

    return format.format(new Date());
}