mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add date to long support for Convert
This commit is contained in:
parent
200dc6c5ea
commit
a0b1a33654
@ -31,7 +31,6 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
* </ul>
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
public class NumberConverter extends AbstractConverter<Number> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -80,6 +79,12 @@ public class NumberConverter extends AbstractConverter<Number> {
|
||||
return ((Number) value).intValue();
|
||||
} else if (value instanceof Boolean) {
|
||||
return BooleanUtil.toInteger((Boolean) value);
|
||||
} else if (value instanceof Date) {
|
||||
return (int)((Date) value).getTime();
|
||||
} else if (value instanceof Calendar) {
|
||||
return (int)((Calendar) value).getTimeInMillis();
|
||||
} else if (value instanceof TemporalAccessor) {
|
||||
return (int)DateUtil.toInstant((TemporalAccessor) value).toEpochMilli();
|
||||
}
|
||||
final String valueStr = convertToStr(value);
|
||||
return StrUtil.isBlank(valueStr) ? null : NumberUtil.parseInt(valueStr);
|
||||
|
@ -16,6 +16,14 @@ public class ConvertToNumberTest {
|
||||
Assert.assertEquals(date.getTime(), dateLong.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateToIntTest(){
|
||||
final DateTime date = DateUtil.parse("2020-05-17 12:32:00");
|
||||
final Integer dateInt = Convert.toInt(date);
|
||||
assert date != null;
|
||||
Assert.assertEquals((int)date.getTime(), dateInt.intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateToAtomicLongTest(){
|
||||
final DateTime date = DateUtil.parse("2020-05-17 12:32:00");
|
||||
|
Loading…
x
Reference in New Issue
Block a user