JodaTime equivalent of DateUtils.truncate()

前端 未结 4 957
慢半拍i
慢半拍i 2020-12-05 09:38

I have never used JodaTime before, but answering this question, How to get ordinal Weekdays in a Month.

I tried it and came up with this ugly code to unset all fiel

4条回答
  •  醉酒成梦
    2020-12-05 10:06

    Joda Time also supports the withFields method in the DateTime type. This can also be used to create a short syntax:

    new DateTime().withDayOfMonth(1).withFields(new LocalTime(0, 0));
    

    In production code the argument to withFields should be factored out to a constant.

提交回复
热议问题