use of cn.hutool.core.date.DateTime in project hutool by looly.
the class RangeTest method rangeToListTest.
@Test
public void rangeToListTest() {
DateTime start = DateUtil.parse("2017-01-01");
DateTime end = DateUtil.parse("2017-01-31");
List<DateTime> rangeToList = DateUtil.rangeToList(start, end, DateField.DAY_OF_YEAR);
Assert.assertEquals(DateUtil.parse("2017-01-01"), rangeToList.get(0));
Assert.assertEquals(DateUtil.parse("2017-01-02"), rangeToList.get(1));
}
use of cn.hutool.core.date.DateTime in project hutool by looly.
the class DateConverter method convertInternal.
@Override
protected java.util.Date convertInternal(Object value) {
if (value == null || (value instanceof CharSequence && StrUtil.isBlank(value.toString()))) {
return null;
}
if (value instanceof TemporalAccessor) {
return wrap(DateUtil.date((TemporalAccessor) value));
} else if (value instanceof Calendar) {
return wrap(DateUtil.date((Calendar) value));
} else if (value instanceof Number) {
return wrap(((Number) value).longValue());
} else {
// 统一按照字符串处理
final String valueStr = convertToStr(value);
final DateTime dateTime = //
StrUtil.isBlank(this.format) ? //
DateUtil.parse(valueStr) : DateUtil.parse(valueStr, this.format);
if (null != dateTime) {
return wrap(dateTime);
}
}
throw new ConvertException("Can not convert {}:[{}] to {}", value.getClass().getName(), value, this.targetType.getName());
}
Aggregations