Package org.joda.time.format

Examples of org.joda.time.format.DateTimeFormatter


        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


    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

    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

    @Override
    protected void write0() throws IOException {
        startArray();

        DateTimeFormatter formatter = ISODateTimeFormat.dateTime();

        int count = 0;

        for (DirectoryListEntry entry : entries) {
            if (count != 0) {
                writeComma();
            }
            count++;

            startObject();

            if (entry.isDirectory()) {
                writeKeyLiteral("subdir");
                writeValue(entry.getKey());

                // writeComma();
                // writeKeyLiteral("content_type");
                // writeValue("application/directory");
            } else {
                FileData file = entry.getFile();

                writeKeyLiteral("name");
                writeValue(file.getKey());

                if (file.hasHash()) {
                    writeComma();
                    writeKeyLiteral("hash");
                    writeValue(Hex.toHex(file.getHash().toByteArray()));
                }

                if (file.hasLength()) {
                    writeComma();
                    writeKeyLiteral("bytes");
                    writeValue(Long.toString(file.getLength()));
                }

                if (file.hasContentType()) {
                    writeComma();
                    writeKeyLiteral("content_type");
                    writeValue(file.getContentType());
                }

                if (file.hasLastModified()) {
                    writeComma();
                    writeKeyLiteral("last_modified");
                    writeValue(formatter.print(file.getLastModified()));
                }
            }
            endObject();
        }
View Full Code Here

    return null;
  }

  @Override
  public String getAsString(FacesContext facesComponent, UIComponent uiComponent, Object object) {
    DateTimeFormatter fmt = DateTimeFormat.forPattern(AvailableTimeZonesBean.STANDARD_DATE_TIME_FORMAT);
    DateTime dateTime = (DateTime)object;

    return fmt.print(dateTime);
  }
View Full Code Here

  @PostConstruct
  public void startupTimeAroundTheWorld(){
    log.info("This bean started on: ");
    for (Iterator<DateTimeZone> iterator = timeZones.iterator(); iterator.hasNext();) {
      DateTimeZone dtz = iterator.next();
      DateTimeFormatter fmt = DateTimeFormat.forPattern(STANDARD_DATE_TIME_FORMAT);
      DateTime dt = new DateTime().withZone(dtz);

      log.info(dtz.getID() + " - "+ fmt.print(dt));
    }
  }
View Full Code Here

  private byte[] processConstant(DboColumnMeta info, ExpressionNode node) {
    //constant is either BigDecimal, BigInteger or a String
    Object constant = node.getState();
    if (info.isJodaType()) {
      DateTimeFormatter fmt;
      if (info.getClassType().getName().equals("org.joda.time.DateTime")) {
        fmt = ISODateTimeFormat.dateTime();
        DateTime dateTime = fmt.parseDateTime(constant.toString());
        return StandardConverters.convertToBytes(dateTime);
      } else if (info.getClassType().getName().equals("org.joda.time.LocalDateTime")) {
        fmt = ISODateTimeFormat.dateTime();
        LocalDateTime localDateTime = fmt.parseLocalDateTime(constant.toString());
        return StandardConverters.convertToBytes(localDateTime);
      } else if (info.getClassType().getName().equals("org.joda.time.LocalDate")) {
        fmt = ISODateTimeFormat.date();
        LocalDate localDate = fmt.parseLocalDate(constant.toString());
        return StandardConverters.convertToBytes(localDate);
      } else if (info.getClassType().getName().equals("org.joda.time.LocalTime")) {
        fmt = ISODateTimeFormat.time();
        LocalTime localTime = fmt.parseLocalTime(constant.toString());
        return StandardConverters.convertToBytes(localTime);
      }
    }
    return info.convertToStorage2(constant);
  }
View Full Code Here

  public void core() {
    LocalDate lt1 = new LocalDate(2000, 1, 1);
    String s1 = lt1.toString();
    Assert.assertEquals("2000-01-01", s1);
   
    DateTimeFormatter fmt = new DateTimeFormatterBuilder()
      .appendLiteral("Year: ")
      .appendYear(4, 4)
      .toFormatter();// minDigits, maxDigits
    Assert.assertEquals("Year: 2000", lt1.toString(fmt));
  }
View Full Code Here

            }

            checkNotNull(columnHandle.getFormatHint(), "formatHint is null");
            String textValue = value.isValueNode() ? value.asText() : value.toString();

            DateTimeFormatter formatter = DateTimeFormat.forPattern(columnHandle.getFormatHint()).withLocale(Locale.ENGLISH).withZoneUTC();
            return formatter.parseMillis(textValue);
        }
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.