Package org.joda.time.format

Examples of org.joda.time.format.DateTimeFormatter


      }
      String s = null;
      if (base != null) {
        // String s = ISODateTimeFormat.basicDateTime().print(base);
        // return s.replace('\ufffd', 'X');
        DateTimeFormatter formatter = getFormatter(flags);
        s = formatter.print(base);
      } else {
        s = "XXXX-XX-XX";
      }
      if (dateTimeZone != null) {
        DateTimeFormatter formatter = DateTimeFormat.forPattern("Z");
        formatter = formatter.withZone(dateTimeZone);
        s = s + formatter.print(0);
      }
      return s;
    }
View Full Code Here


    private static final DateTimeZone SAO_PAOLO = DateTimeZone.forID("America/Sao_Paulo");
    private static final DateTimeZone CHICAGO = DateTimeZone.forID("America/Chicago");

    public static void main(String[] args) {
       
        DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZZ");

            //Setting 2011 Fall DST day.
            DateTime st = new DateTime(2011, 11, 6, 0, 0, CHICAGO);
            DateTime et = new DateTime(2011, 11, 6, 0, 0, CHICAGO);
            //======================================
        for (int i = 0; i <= 24; i++) {
            try {
                if (i > 0) {
                    st = st.minuteOfDay().addToCopy(60);
                }
                et = et.minuteOfDay().addToCopy(60);

                System.out.println("START TIME = { " + fmt.print(st)
                        + " } END TIME =  {" + fmt.print(et) + " }");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
            //=====================================
View Full Code Here

        assertEquals(new LocalDate(2010, 6, 30), LocalDate.parse("2010-06-30"));
        assertEquals(new LocalDate(2010, 1, 2), LocalDate.parse("2010-002"));
    }

    public void testParse_formatter() throws Throwable {
        DateTimeFormatter f = DateTimeFormat.forPattern("yyyy--dd MM").withChronology(ISOChronology.getInstance(PARIS));
        assertEquals(new LocalDate(2010, 6, 30), LocalDate.parse("2010--30 06", f));
    }
View Full Code Here

            return null;
        }
        if (input.size() == 1) {
            return DataType.toDateTime(input.get(0)).toString();
        } else if (input.size() == 2) {
            DateTimeFormatter dtf = DateTimeFormat.forPattern(DataType.toString(input.get(1)));
            return DataType.toDateTime(input.get(0)).toString(dtf);
        } else {
            return null;
        }
    }
View Full Code Here

        String date = input.get(0).toString();
        String format = input.get(1).toString();

        // See http://joda-time.sourceforge.net/api-release/org/joda/time/format/DateTimeFormat.html
        DateTimeFormatter parser = DateTimeFormat.forPattern(format);
        DateTime result;
        try {
            result = parser.parseDateTime(date);
        } catch(Exception e) {
            return null;
        }

        return result.toString();
View Full Code Here

    public DateTime exec(Tuple input) throws IOException {
        if (input == null || input.size() < 1 || input.get(0) == null) {
            return null;
        }
        DateTimeFormatter dtf = DateTimeFormat.forPattern(DataType
                .toString(input.get(1)));
        DateTimeZone dtz = DateTimeZone.forOffsetMillis(DateTimeZone.forID(
                DataType.toString(input.get(2))).getOffset(null));
        return dtf.withZone(dtz).parseDateTime(DataType.toString(input.get(0)));
    }
View Full Code Here

        assertEquals(new LocalTime(1, 20), LocalTime.parse("01:20"));
        assertEquals(new LocalTime(14, 50, 30, 432), LocalTime.parse("14:50:30.432"));
    }

    public void testParse_formatter() throws Throwable {
        DateTimeFormatter f = DateTimeFormat.forPattern("HH mm").withChronology(ISOChronology.getInstance(PARIS));
        assertEquals(new LocalTime(13, 30), LocalTime.parse("13 30", f));
    }
View Full Code Here

            return p.getDoubleValue();

        case DataType.DATETIME:
            tok = p.nextToken();
            if (tok == JsonToken.VALUE_NULL) return null;
            DateTimeFormatter formatter = ISODateTimeFormat.dateTimeParser();
            return formatter.withOffsetParsed().parseDateTime(p.getText());

        case DataType.BYTEARRAY:
            tok = p.nextToken();
            if (tok == JsonToken.VALUE_NULL) return null;
            byte[] b = p.getText().getBytes();
View Full Code Here

        assertEquals(new LocalDateTime(2010, 6, 30, 1, 20), LocalDateTime.parse("2010-06-30T01:20"));
        assertEquals(new LocalDateTime(2010, 1, 2, 14, 50, 30, 432), LocalDateTime.parse("2010-002T14:50:30.432"));
    }

    public void testParse_formatter() throws Throwable {
        DateTimeFormatter f = DateTimeFormat.forPattern("yyyy--dd MM HH").withChronology(ISOChronology.getInstance(PARIS));
        assertEquals(new LocalDateTime(2010, 6, 30, 13, 0), LocalDateTime.parse("2010--30 06 13", f));
    }
View Full Code Here

            return null;
        }
        String dtStr = DataType.toString(input.get(0));
        //DateTimeZone dtz = extractDateTimeZone(dtStr);
        //The timezone in the customized format is not predictable
        DateTimeFormatter dtf = DateTimeFormat.forPattern(DataType
                .toString(input.get(1)));
        //if (dtz == null) {
            return dtf.parseDateTime(dtStr);
        //} else {
        //    return dtf.withZone(dtz).parseDateTime(dtStr);
        //}
    }
View Full Code Here

TOP

Related Classes of org.joda.time.format.DateTimeFormatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.