从LocalDateTime和LocalTime

时间:2017-03-02 15:34:04

标签: java jodatime

给定日期时间和时间,

    LocalDateTime rightDateWrongTime = new LocalDateTime("2017-03-02T15:23:00.000");
    LocalTime rightTime = new LocalTime("17:30:00");

我可以将它们组合起来:

    LocalDateTime rightDateRightTime = rightDateWrongTime.withTime(
        rightTime.getHourOfDay(), rightTime.getMinuteOfHour(), 
        rightTime.getSecondOfMinute(), rightTime.getMillisOfSecond());

感觉应该有一个更方便的方法。像这样:

    LocalDateTime rightDateRightTime = rightDateWrongTime.withTime(rightTime);

但我找不到任何东西。是否存在类似的方法?

1 个答案:

答案 0 :(得分:0)

您可以使用:

LocalDateTime rightDateRightTime = rightDateWrongTime.withFields(rightTime);

它对我有用(我使用joda 2.2 - 不确定何时引入withFields方法)