插件开发工具库,推荐依赖该工具库。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

25 lines
800 B

package com.fanruan.api.util;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import org.junit.Assert;
import org.junit.Test;
public class DateKitTest {
@Test
public void string2Date() throws Exception{
DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd");
Date myDate = dateFormat2.parse("2019-02-20");
Assert.assertEquals(DateKit.string2Date("2019-02-20", false), myDate);
Assert.assertEquals(DateKit.string2Date("abcd", false), new Date());
Assert.assertEquals(DateKit.string2Date("abcd", true), null);
}
@Test
public void testGetDate2Str() throws Exception {
String date = DateKit.getDate2Str("yyyy-MM-dd", new Date(0));
Assert.assertEquals(date, "1970-01-01");
}
}