package com.business;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.google.common.collect.Lists;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations= "classpath:spring/applicationContext.xml")
public class DateUtilTest {
public static void main(String[] args) {
System.out.println("************************************************");
System.out.println("************************************************");
List<Long> ids = Lists.newArrayList(12L,123L,23L,432L,235L,235L);
String itemIds = StringUtils.join(ids.toArray(), ",");
System.out.println(itemIds);
System.out.println("************************************************");
System.out.println("************************************************");
}
@Test
public void getSomeDateTest(){
//截去一个时间的时分秒
Date t = new Date();
Date tt = DateUtils.truncate(t1, Calendar.DATE);
//2017-05-24 10:26:50
System.out.println(t);
//2017-05-24 00:00:00
System.out.println(tt);
Date t1 = new Date();
Calendar cal = new GregorianCalendar();
cal.add(Calendar.DATE, 1);
cal.add(Calendar.HOUR_OF_DAY, -1);
Date t2 = cal.getTime();
System.out.println(t1.toString());
System.out.println(t2.toString());
//时间比较,忽略时分秒
System.out.println(DateUtils.truncatedCompareTo(t1, t2, Calendar.DATE));
}
}
两个时间相比,只精确到天以上,忽略时分秒
最新推荐文章于 2024-07-08 17:25:48 发布