根据问题标题,我想知道是否有比这更简洁的内容:
new YearMonth(2014, 1).toLocalDate(1).toLocalDateTime(new LocalTime())
也许是实用方法或实例方法?
最佳答案
您的示例使用当前时间。如果这是任意的,并且午夜就可以,请尝试:
new LocalDateTime(1980, 1, 1, 0, 0).withFields(new YearMonth(2014, 1))
然后,为了更简洁,您可以将 LocalDateTime 拉入常量:
FIRST_OF_MONTH.withFields(new LocalDateTime(2014, 1))
或者,相当于您建议的“toLocalDateTime”:
LocalDateTime.now().withFields(new LocalDateTime(2014, 1))
关于java - 如何轻松将 Joda YearMonth 转换为 LocalDateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20148854/