Package org.joda.time.format

Examples of org.joda.time.format.DateTimeFormatter


    if (Strings.isEmpty(value))
    {
      return null;
    }

    DateTimeFormatter format = getFormat(locale);
    if (format == null)
    {
      throw new IllegalStateException("format must be not null");
    }

    if (applyTimeZoneDifference)
    {
      TimeZone zone = getClientTimeZone();
      DateTime dateTime = null;

      // set time zone for client
      format = format.withZone(getTimeZone());

      try
      {
        // parse date retaining the time of the submission
        dateTime = format.parseDateTime(value);
      }
      catch (RuntimeException e)
      {
        throw new ConversionException(e);
      }
      // apply the server time zone to the parsed value
      if (zone != null)
      {
        dateTime = dateTime.withZoneRetainFields(DateTimeZone.forTimeZone(zone));
      }

      return dateTime.toDate();
    }
    else
    {
      try
      {
        DateTime date = format.parseDateTime(value);
        return date.toDate();
      }
      catch (RuntimeException e)
      {
        throw new ConversionException(e);
View Full Code Here


   *      java.util.Locale)
   */
  public String convertToString(Date value, Locale locale)
  {
    DateTime dt = new DateTime((value).getTime(), getTimeZone());
    DateTimeFormatter format = getFormat(locale);

    if (applyTimeZoneDifference)
    {
      TimeZone zone = getClientTimeZone();
      if (zone != null)
      {
        // apply time zone to formatter
        format = format.withZone(DateTimeZone.forTimeZone(zone));
      }
    }
    return format.print(dt);
  }
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 = parser.parseDateTime(date);

        return result.toString();
    }
View Full Code Here

      "2003-10-11T22:14:15.003Z", "2003-08-24T05:14:15.000003-07:00",
      "2012-04-13T11:11:11-08:00", "2012-04-13T08:08:08.0001+00:00"
    };

    SyslogParser parser = new SyslogParser();
    DateTimeFormatter jodaParser = ISODateTimeFormat.dateTimeParser();

    for (String ex : examples) {
      Assert.assertEquals(
          "Problem parsing date string: " + ex,
          jodaParser.parseMillis(ex),
          parser.parseRfc5424Date(ex));
    }
  }
View Full Code Here

    if (Strings.isEmpty(value))
    {
      return null;
    }

    DateTimeFormatter format = getFormat(locale);
    if (format == null)
    {
      throw new IllegalStateException("format must be not null");
    }

    if (applyTimeZoneDifference)
    {
      TimeZone zone = getClientTimeZone();
      DateTime dateTime = null;
     
      // set time zone for client
      format = format.withZone(getTimeZone());       

      try
      {
        // parse date retaining the time of the submission
        dateTime = format.parseDateTime(value);       
      }
      catch (RuntimeException e)
      {
        throw new ConversionException(e);
      }
      // apply the server time zone to the parsed value
      if (zone != null)
      {
        dateTime = dateTime.withZoneRetainFields(DateTimeZone.forTimeZone(zone));
      }     
     
      return dateTime.toDate();
    }
    else
    {
      try
      {
        DateTime date = format.parseDateTime(value);
        return date.toDate();
      }
      catch (RuntimeException e)
      {
        throw new ConversionException(e);
View Full Code Here

   *      java.util.Locale)
   */
  public String convertToString(Date value, Locale locale)
  {
    DateTime dt = new DateTime((value).getTime(), getTimeZone());
    DateTimeFormatter format = getFormat(locale);

    if (applyTimeZoneDifference)
    {
      TimeZone zone = getClientTimeZone();
      if (zone != null)
      {
        // apply time zone to formatter
        format = format.withZone(DateTimeZone.forTimeZone(zone));
      }
    }
    return format.print(dt);
  }
View Full Code Here

    List<DateTimeFormatter> formatters = DateTimeFormat.forPatterns(formats, timeZone, false);
   
    PosixLtVector.Builder result = new PosixLtVector.Builder();
    int resultLength = Math.max(x.length(), formats.length());
    for(int i=0;i!=resultLength;++i) {
      DateTimeFormatter formatter = formatters.get(i % formatters.size());
      String string = x.getElementAsString(i % x.length());
      try {
        result.add(parseIgnoreTrailingCharacters(formatter, string));
      } catch(IllegalArgumentException e) {
        result.addNA();
View Full Code Here

   
    StringVector.Builder result = new StringVector.Builder();
    int resultLength = Math.max(dateTimes.length(), patterns.length());

    for(int i=0;i!=resultLength;++i) {
      DateTimeFormatter formatter = formatters.get(i % formatters.size());
      DateTime dateTime = dateTimes.getElementAsDateTime(i % dateTimes.length());
     
      result.add(formatter.print(dateTime));
    }
   
    return result.build();
  }
View Full Code Here

    verifyFormat("2009-07-01 00:00:00", "%Y-%m-%d %H:%M:%OS", new DateTime(2009,7,1,0,0,0));
  }


  private void verifyFormat(String x, String format, DateTime dateTime) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern(format);
    assertThat(formatter.print(dateTime), equalTo(x));
    assertThat(formatter.parseDateTime(x), equalTo(dateTime));
  }
View Full Code Here

        if("isis:String".equals(dataType)) {
            return (T)getChildTextValue(chldEl);
        }
        if("isis:LocalDate".equals(dataType)) {
            final String str = getChildTextValue(chldEl);
            final DateTimeFormatter forPattern = DateTimeFormat.forPattern("dd-MMM-yyyy").withLocale(Locale.ENGLISH);
            return (T)forPattern.parseLocalDate(str);
        }
        if("isis:Byte".equals(dataType)) {
            final String str = getChildTextValue(chldEl);
            return (T)new Byte(str);
        }
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.