Package org.joda.time.format

Examples of org.joda.time.format.DateTimeFormatter


        int rowCount = 0;
        int colCount = 0;
       
        //Set the filename
        DateTime dt = new DateTime();
        DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd_HHmmss");
        String filename = dt.toString(fmt);
       
       
        // Create Excel Workbook and Sheet
        HSSFWorkbook wb = new HSSFWorkbook();
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

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

        // Need to get the ISO8601 date for properties
        DateTime dt = new DateTime( 0 );
        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

   *      java.util.Locale)
   */
  public String convertToString(Date value, Locale locale)
  {
    DateTime dt = new DateTime((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

        return type.equals(GregorianCalendar.class);
    }

    public Object fromString(String str) {
        for (int i = 0; i < formattersUTC.length; i++) {
            DateTimeFormatter formatter = formattersUTC[i];
            try {
                DateTime dt = formatter.parseDateTime(str);
                Calendar calendar = dt.toCalendar(Locale.getDefault());
                calendar.setTimeZone(TimeZone.getDefault());
                return calendar;
            } catch (IllegalArgumentException e) {
                // try with next formatter
            }
        }
        String timeZoneID = TimeZone.getDefault().getID();
        for (int i = 0; i < formattersNoUTC.length; i++) {
            try {
                DateTimeFormatter formatter = formattersNoUTC[i].withZone(DateTimeZone.forID(timeZoneID));
                DateTime dt = formatter.parseDateTime(str);
                Calendar calendar = dt.toCalendar(Locale.getDefault());
                calendar.setTimeZone(TimeZone.getDefault());
                return calendar;
            } catch (IllegalArgumentException e) {
                // try with next formatter
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

    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

  /**
   * @return formatter The formatter for the current conversion
   */
  protected DateTimeFormatter getFormat()
  {
    DateTimeFormatter dtf = DateTimeFormat.forPattern(getDatePattern()).withPivotYear(2000);
    return dtf;
  }
View Full Code Here

   * @see org.apache.wicket.util.convert.IConverter#convertToObject(java.lang.String,
   *      java.util.Locale)
   */
  public Object convertToObject(String value, Locale locale)
  {
    DateTimeFormatter format = getFormat();

    if (applyTimeZoneDifference)
    {
      TimeZone zone = getClientTimeZone();
      // instantiate now/ current time
      MutableDateTime dt = new MutableDateTime();
      if (zone != null)
      {
        // set time zone for client
        format = format.withZone(DateTimeZone.forTimeZone(zone));
        dt.setZone(DateTimeZone.forTimeZone(zone));
      }
      // parse date retaining the time of the submission
      format.parseInto(dt, value, 0);
      // apply the server time zone to the parsed value
      dt.setZone(getTimeZone());
      return dt.toDate();
    }
    else
    {
      return format.parseDateTime(value).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.