Package org.joda.time.format

Examples of org.joda.time.format.DateTimeFormatter


  @Test
  public void shouldExtractAddHeadersUsingSpecifiedSerializer()
      throws Exception {
    long now = (System.currentTimeMillis() / 60000L) * 60000L;
    String pattern = "yyyy-MM-dd HH:mm:ss,SSS";
    DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern);
    String body = formatter.print(now);
    System.out.println(body);
    Context context = new Context();
    // Skip the second group
    context.put(RegexExtractorInterceptor.REGEX,
        "^(\\d\\d\\d\\d-\\d\\d-\\d\\d\\s\\d\\d:\\d\\d)(:\\d\\d,\\d\\d\\d)");
View Full Code Here


    Context context = new Context();
    String pattern = "yyyy-MM-dd HH:mm:ss";
    context.put("pattern", pattern);
    fixture.configure(context);

    DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern);
    long time = (System.currentTimeMillis() / 1000L) * 1000L;
    Assert.assertEquals(String.valueOf(time),
        fixture.serialize(formatter.print(time)));
  }
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

            properties.add( new DefaultDavProperty( DavPropertyName.ISCOLLECTION, "0" ) );
        }

        // Need to get the ISO8601 date for properties
        DateTime dt = new DateTime( localResource.lastModified() );
        DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
        String modifiedDate = fmt.print( dt );

        properties.add( new DefaultDavProperty( DavPropertyName.GETLASTMODIFIED, modifiedDate ) );

        properties.add( new DefaultDavProperty( DavPropertyName.CREATIONDATE, modifiedDate ) );
View Full Code Here

    }
   
    @Override
    public String toString() {
      DateTime dateTime = new DateTime(this.timeInMillis);
      DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy");
       
      return dateTime.toString(formatter);
    }
View Full Code Here

      return dateTime.toString(formatter);
    }

    public String getFormatedDate() {
      DateTime dateTime = new DateTime(this.timeInMillis);
      DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy");
       
      return dateTime.toString(formatter);
    }
View Full Code Here

     setTimeInMillis(dateTime.getMillis());
  }
 
  public String getFormatedTime() {
    DateTime dateTime = new DateTime(this.timeInMillis);
    DateTimeFormatter fmt = DateTimeFormat.forPattern("EEEE, dd 'de' MMMM 'de' yyyy - HH:mm:ss");
    return dateTime.toString(fmt);
  }
View Full Code Here

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

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

    if (applyTimeZoneDifference)
    {
      TimeZone zone = getClientTimeZone();
      // instantiate now/ current time
      MutableDateTime dt = new MutableDateTime(new DateMidnight());
      if (zone != null)
      {
        // set time zone for client
        format = format.withZone(DateTimeZone.forTimeZone(zone));
        dt.setZone(DateTimeZone.forTimeZone(zone));
      }
      try
      {
        // parse date retaining the time of the submission
        int result = format.parseInto(dt, value, 0);
        if (result < 0)
        {
          throw new ConversionException(new ParseException("unable to parse date " +
              value, ~result));
        }
      }
      catch (RuntimeException e)
      {
        throw new ConversionException(e);
      }
      // apply the server time zone to the parsed value
      dt.setZone(getTimeZone());
      return dt.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(Object value, Locale locale)
  {
    DateTime dt = new DateTime(((Date)value).getTime(), getTimeZone());
    DateTimeFormatter format = getFormat();

    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

public class ModelUtil {

    private ModelUtil() {}

    public static Date stringToDate(String dateString){
        DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();
        return fmt.parseDateTime(dateString).toDate();
    }
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.