Package org.joda.time.format

Examples of org.joda.time.format.DateTimeFormatter.parseDateTime()


        // 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


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

   * @param dateStr date str
   * @return datetime
   */
  public DateTime toDateTime(String dateStr) {
    DateTimeFormatter df = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    DateTime date = df.parseDateTime(dateStr);
    return date;
  }

  public DateTime toDateTime(String dateStr, String format) {
    if (ValidateUtils.me().isNullOrEmpty(format)) {
View Full Code Here

  public DateTime toDateTime(String dateStr, String format) {
    if (ValidateUtils.me().isNullOrEmpty(format)) {
      format = "yyyy-MM-dd HH:mm:ss";
    }
    DateTimeFormatter df = DateTimeFormat.forPattern(format);
    DateTime date = df.parseDateTime(dateStr);
    return date;
  }

  /**
   * 时间转换为字符串
 
View Full Code Here

    public void testConversion() {
        String input = "21/Jan/2012:02:34:42 +0100";
        String pattern = "dd/MMM/yyyy:HH:mm:ss Z";
       
        DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern);
        DateTime actual = dtf.parseDateTime(input);
       
        DateTime expected = new DateTime(2012, 1, 21, 2, 34, 42, DateTimeZone.forOffsetHours(1));
        Assert.assertTrue(expected.isEqual(actual));
    }
}
View Full Code Here

   
    DateTime dateTime = new DateTime();
   
    if (dateTimeString != null) {
      DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(dateFormatPattern);
      dateTime = dateTimeFormatter.parseDateTime(dateTimeString);
    }
     
    return dateTime;
   
  }
View Full Code Here

        }
        else {
            formatter = DATE_FORMAT; // "yyyy-MM-dd"
        }

        return formatter.parseDateTime(stamp);
    }

    /**
     *
     * @param time
View Full Code Here

     * @param time
     * @return
     */
    public static DateTime toTime(String time) {
        DateTimeFormatter formatter = time.contains(" ") ? DATE_TIME_FORMAT : (time.contains("T") ? TIMESTAMP_FORMAT : DATE_FORMAT);
        return formatter.parseDateTime(time);
    }

    /**
     *
     * @param runtime
View Full Code Here

            facet.setEstimatedCalories(day.getInt("estimatedCalories"));
            facet.setPredictedCalories(day.getInt("predictedCalories"));
            facet.json = day.getString("minutes");
            facet.lastSync = d.getMillis();

            DateTime date = formatter.parseDateTime(day.getString("date"));
            facet.date = TimeUtils.dateFormatter.print(date.getMillis());

            long fromMidnight = TimeUtils.fromMidnight(date.getMillis(), timeZone.toTimeZone());
            long toMidnight = TimeUtils.toMidnight(date.getMillis(), timeZone.toTimeZone());
            //Sets the start and end times for the facet so that it can be uniquely defined
View Full Code Here

        //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
Copyright © 2018 www.massapi.com. 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.