Example usage for org.joda.time.format DateTimeFormatter parseDateTime

List of usage examples for org.joda.time.format DateTimeFormatter parseDateTime

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormatter parseDateTime.

Prototype

public DateTime parseDateTime(String text) 

Source Link

Document

Parses a date-time from the given text, returning a new DateTime.

Usage

From source file:org.jlucrum.datafetcher.FetcherOsuusPankki.java

License:Open Source License

public static void main(String[] av) {
    String patternString = "yyyy-MM-dd";
    DateTimeFormatter formatter = DateTimeFormat.forPattern(patternString);
    String name = "Metso Oyj";

    DateTime fromDate = formatter.parseDateTime("2009-05-01");
    DateTime toDate = formatter.parseDateTime("2011-05-05");
    ;/*from w w  w  .  j ava  2  s  . c o m*/
    int type = 0;
    FetcherOsuusPankki instance = new FetcherOsuusPankki();

    Map<String, Double> result = instance.fetchDataPeriod(name, fromDate, toDate, type);
    //        
    //        for (Entry<String,Double> entry:result.entrySet()) {
    //            System.out.printf("%s, %f\n", entry.getKey(), entry.getValue());
    //        }
}

From source file:org.jongo.demo.Demo.java

License:Open Source License

private static void generateDemoDatabase(final DatabaseConfiguration dbcfg) {
    final String database = dbcfg.getDatabase();
    QueryRunner run = new QueryRunner(JDBCConnectionFactory.getDataSource(dbcfg));

    l.info("Generating Demo resources in database " + database);
    update(run, getCreateUserTable());/* w  w w.  j a  v  a 2s.  co m*/
    update(run, getCreateMakersTable());
    update(run, getCreateCarsTable());
    update(run, getCreateCommentsTable());
    update(run, getCreatePicturesTable());
    update(run, getCreateSalesStatsTable());
    update(run, getCreateSalesByMakerAndModelStatsTable());
    update(run, getCreateEmptyTable());

    l.info("Generating Demo Data in database " + database);

    final String insertUserQuery = "INSERT INTO users (name, age, birthday, credit) VALUES (?,?,?,?)";
    update(run, insertUserQuery, "foo", 30, "1982-12-13", 32.5);
    update(run, insertUserQuery, "bar", 33, "1992-01-15", 0);

    for (CarMaker maker : CarMaker.values()) {
        update(run, "INSERT INTO maker (name, realname) VALUES (?,?)", maker.name(), maker.getRealName());
    }

    final String insertCar = "INSERT INTO car (maker, model, year, fuel, transmission, currentMarketValue, newValue) VALUES (?,?,?,?,?,?,?)";
    update(run, insertCar, "CITROEN", "C2", 2008, "Gasoline", "Manual", 9000, 13000);
    update(run,
            "INSERT INTO car (maker, model, year, transmission, currentMarketValue, newValue) VALUES (?,?,?,?,?,?)",
            "FIAT", "500", 2010, "Manual", 19000, 23.000);
    update(run, insertCar, "BMW", "X5", 2011, "Diesel", "Automatic", 59000, 77000);

    final String insertComment = "INSERT INTO comments (car_id, car_comment) VALUES (?,?)";
    update(run, insertComment, 0, "The Citroen C2 is a small car with a great attitude");
    update(run, insertComment, 0, "I Love my C2");
    update(run, insertComment, 2,
            "BMW's X5 costs too much for what it's worth. Checkout http://www.youtube.com/watch?v=Bg1TB4dRobY");

    final String insertPicture = "INSERT INTO pictures (car_id, picture) VALUES (?,?)";
    update(run, insertPicture, 0, "http://www.babez.de/citroen/c2/picth01.jpg");
    update(run, insertPicture, 0, "http://www.babez.de/citroen/c2/pic02.jpg");
    update(run, insertPicture, 0, "http://www.babez.de/citroen/c2/picth03.jpg");

    update(run, insertPicture, 1, "http://www.dwsauto.com/wp-content/uploads/2008/07/fiat-500-photo.jpg");
    update(run, insertPicture, 1, "http://www.cochesadictos.com/coches/fiat-500/imagenes/index1.jpg");
    update(run, insertPicture, 1, "http://www.cochesadictos.com/coches/fiat-500/imagenes/index4.jpg");

    update(run, insertPicture, 2, "http://www.coches21.com/fotos/100/bmw_x5_457.jpg");
    update(run, insertPicture, 2, "http://www.coches21.com/fotos/100/bmw_x5_460.jpg");
    update(run, insertPicture, 2, "http://www.coches21.com/modelos/250/bmw_x5_65.jpg");

    // generate some random data for the stats page
    DateTimeFormatter isofmt = ISODateTimeFormat.dateTime();
    DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSSSSSSSS");
    DateTime dt;// = isofmt.parseDateTime("2012-01-16T13:34:00.000Z");
    for (int year = 2000; year < 2012; year++) {
        for (int month = 1; month <= 12; month++) {
            int val = 1910 + new Random().nextInt(100);
            dt = isofmt.parseDateTime(year + "-" + month + "-01T01:00:00.000Z");
            update(run, "INSERT INTO sales_stats (year, month, sales, last_update) VALUES (?,?,?,?)", year,
                    month, val, fmt.print(dt));
            for (CarMaker maker : CarMaker.values()) {
                val = new Random().nextInt(100);
                update(run,
                        "INSERT INTO maker_stats (year, month, sales, maker, last_update) VALUES (?,?,?,?,?)",
                        year, month, val, maker.name(), fmt.print(dt));
            }
        }
    }

    update(run, "SET TABLE maker READONLY TRUE");

    //load the sp
    update(run, "CREATE FUNCTION simpleStoredProcedure () RETURNS TINYINT RETURN 1");
    update(run,
            "CREATE PROCEDURE insert_comment (IN car_id INTEGER, IN car_comment VARCHAR(255)) MODIFIES SQL DATA INSERT INTO comments VALUES (DEFAULT, car_id, car_comment)");
    update(run,
            "CREATE PROCEDURE get_year_sales (IN in_year INTEGER, OUT out_total INTEGER) READS SQL DATA SELECT COUNT(sales) INTO out_total FROM sales_stats WHERE year = in_year");
    update(run, getCreateView());

}

From source file:org.jruby.ext.krypt.asn1.Asn1Codecs.java

License:Open Source License

private static IRubyObject decodeTime(Ruby runtime, byte[] value, DateTimeFormatter formatter) {
    if (value == null)
        throw Errors.newASN1Error(runtime, "Invalid time encoding");
    try {// w  ww.jav a 2s. co  m
        DateTime dateTime = formatter.parseDateTime(new String(value, Charset.forName("US-ASCII")));
        return RubyTime.newTime(runtime, dateTime);
    } catch (Exception ex) {
        throw Errors.newASN1Error(runtime, "Error while decoding time value: " + ex.getMessage());
    }
}

From source file:org.jspringbot.keyword.date.DateHelper.java

License:Open Source License

public DateTime getParseDateTime(String dateStr, String pattern) {
    LOG.keywordAppender().appendProperty("Date String", dateStr).appendProperty("Parse Pattern", pattern);

    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(pattern);
    return dateTimeFormatter.parseDateTime(dateStr);
}

From source file:org.jspringbot.keyword.date.DateHelper.java

License:Open Source License

public String parseDateTime(String dateStr, String pattern) {
    LOG.keywordAppender().appendProperty("Date String", dateStr).appendProperty("Parse Pattern", pattern);

    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(pattern);
    current = dateTimeFormatter.parseDateTime(dateStr);

    // show the log for print
    return formatDateTime();
}

From source file:org.jspringbot.keyword.date.DateHelper.java

License:Open Source License

public String isoParseDateTime(String dateStr) {
    LOG.keywordAppender().appendProperty("Date String", dateStr);

    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    current = fmt.parseDateTime(dateStr);

    // show the log for print
    return formatDateTime();
}

From source file:org.jtalks.jcommune.web.validation.editors.DateTimeEditor.java

License:Open Source License

@Override
public void setAsText(String text) {
    if (text != null && !text.isEmpty()) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(this.format);
        try {//  ww w .j a v a  2 s  .  c o  m
            setValue(dateTimeFormatter.parseDateTime(text));
        } catch (IllegalArgumentException e) {
            setValue(null);
        }
    }
}

From source file:org.jtotus.database.NetworkGoogle.java

License:Open Source License

public HashMap<String, Double> fetchPeriodAsMap(String stockName, DateTime startDate, DateTime endDate) {
    HashMap<String, Double> retMap = new HashMap<String, Double>(500);
    DefaultHttpClient client = new DefaultHttpClient();
    HttpGet httpGet = null;/*from  w  ww  .  jav a2s.  c o  m*/
    try {
        DateTimeFormatter formatterOUT = DateTimeFormat.forPattern(timePatternForWrite);
        DateTimeFormatter formatterIN = DateTimeFormat.forPattern(timePatternForRead);

        String query = url + "?q=" + names.getHexName(stockName) + "&" + "startdate="
                + formatterOUT.print(startDate) + "&" + "enddate=" + formatterOUT.print(endDate) + "&"
                + "&num=30&output=csv";

        System.out.printf("HttpGet:%s : date:%s\n", query, formatterOUT.print(startDate));
        httpGet = new HttpGet(query);

        HttpResponse response = client.execute(httpGet);
        StatusLine status = response.getStatusLine();
        if (status.getStatusCode() != 200) {
            throw new IOException("Invalid response from server: " + status.toString());
        }

        HttpEntity entity = response.getEntity();

        BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));

        //            Date, Open,High,Low,Close,Volume
        String line = reader.readLine(); //Header
        while ((line = reader.readLine()) != null) {
            String[] values = line.split(",");
            DateTime date = formatterIN.parseDateTime(values[0]);
            double value = Double.parseDouble(values[4]);
            retMap.put(formatter.print(date), value);
        }

    } catch (IOException ex) {
        System.err.printf("Unable to find market data for: %s - %s\n", names.getHexName(stockName), stockName);
    } catch (IllegalArgumentException ex) {
        System.err.printf("Unable to find market data for: %s - %s\n", names.getHexName(stockName), stockName);
    } finally {
        if (httpGet != null) {

        }
    }

    System.out.printf("NetworkGoogle fetched : %d values\n", retMap.size());
    return retMap;
}

From source file:org.kalypso.ogc.sensor.util.TimestampHelper.java

License:Open Source License

/**
 * This function converts the timestamp text (e.g. 11:00) into UTC.
 * /*from  w w w  .j  a va2s  .c o  m*/
 * @param timestampText
 *          The timestamp text in the kalypso timezone.
 * @return The timestamp text in UTC.
 */
public static String convertToUTC(final String timestampText) {
    /* Nothing to do. */
    if (timestampText == null || timestampText.length() == 0)
        return ""; //$NON-NLS-1$

    /* Create the date time formatter. */
    final DateTimeFormatter formatter = createDateTimeFormatter();
    final DateTimeFormatter formatterZone = formatter
            .withZone(DateTimeZone.forTimeZone(KalypsoCorePlugin.getDefault().getTimeZone()));

    /* Get the timestamp in the kalypso timezone. */
    final DateTime timestampZone = formatterZone.parseDateTime(timestampText);
    final DateTime timestampUTC = new DateTime(timestampZone.toDate(),
            DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC"))); //$NON-NLS-1$

    return timestampUTC.toString("HH:mm"); //$NON-NLS-1$
}

From source file:org.kuali.kpme.tklm.common.BatchJobServiceImpl.java

License:Educational Community License

@Override
public void scheduleLeaveCarryOverJobs(LeavePlan leavePlan) throws SchedulerException {
    DateTimeFormatter formatter = DateTimeFormat.forPattern("MM/dd");
    DateTime scheduleDate = formatter.parseDateTime(leavePlan.getBatchPriorYearCarryOverStartDate())
            .plus(leavePlan.getBatchPriorYearCarryOverStartTime().getTime());
    scheduleLeaveCarryOverJob(leavePlan, scheduleDate);
}