use of cn.hutool.core.date.DateTime in project hutool by looly.
the class RangeTest method rangeNotContains.
@Test
public void rangeNotContains() {
// 开始区间
DateTime start = DateUtil.parse("2017-01-01");
DateTime end = DateUtil.parse("2017-01-30");
DateRange startRange = DateUtil.range(start, end, DateField.DAY_OF_YEAR);
// 结束区间
DateTime start1 = DateUtil.parse("2017-01-01");
DateTime end1 = DateUtil.parse("2017-01-31");
DateRange endRange = DateUtil.range(start1, end1, DateField.DAY_OF_YEAR);
// 差集
List<DateTime> dateTimes1 = DateUtil.rangeNotContains(startRange, endRange);
Assert.assertEquals(1, dateTimes1.size());
Assert.assertEquals(DateUtil.parse("2017-01-31"), dateTimes1.get(0));
}
use of cn.hutool.core.date.DateTime in project hutool by looly.
the class ConvertToNumberTest method dateToAtomicLongTest.
@Test
public void dateToAtomicLongTest() {
final DateTime date = DateUtil.parse("2020-05-17 12:32:00");
final AtomicLong dateLong = Convert.convert(AtomicLong.class, date);
assert date != null;
Assert.assertEquals(date.getTime(), dateLong.longValue());
}
use of cn.hutool.core.date.DateTime in project hutool by looly.
the class ConvertToNumberTest method dateToIntTest.
@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());
}
use of cn.hutool.core.date.DateTime in project hutool by looly.
the class DateTimeTest method seasonTest.
@Test
public void seasonTest() {
DateTime dateTime = new DateTime("2017-01-05 12:34:23", DatePattern.NORM_DATETIME_FORMAT);
// 季度(非季节)
Season season = dateTime.seasonEnum();
Assert.assertEquals(Season.SPRING, season);
dateTime = new DateTime("2017-04-05 12:34:23", DatePattern.NORM_DATETIME_FORMAT);
// 季度(非季节)
season = dateTime.seasonEnum();
Assert.assertEquals(Season.SUMMER, season);
dateTime = new DateTime("2017-09-05 12:34:23", DatePattern.NORM_DATETIME_FORMAT);
// 季度(非季节)
season = dateTime.seasonEnum();
Assert.assertEquals(Season.AUTUMN, season);
dateTime = new DateTime("2017-12-05 12:34:23", DatePattern.NORM_DATETIME_FORMAT);
// 季度(非季节)
season = dateTime.seasonEnum();
Assert.assertEquals(Season.WINTER, season);
}
use of cn.hutool.core.date.DateTime in project hutool by looly.
the class DateTimeTest method toStringTest.
@Test
public void toStringTest() {
DateTime dateTime = new DateTime("2017-01-05 12:34:23", DatePattern.NORM_DATETIME_FORMAT);
Assert.assertEquals("2017-01-05 12:34:23", dateTime.toString());
String dateStr = dateTime.toString("yyyy/MM/dd");
Assert.assertEquals("2017/01/05", dateStr);
}
Aggregations