提示:在项目整合完Junit之后,可以直接拷贝使用
package com.xxx.xxx.xxx;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxx.xxx.xxxApplication;
import com.utils.RestTemplateUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = xxxApplication.class)
public class TestInterface {
@Autowired
private RestTemplateUtil restTemplateUtil;
/**
* 日期操纵
* */
@Test
public void test01() throws ParseException {
//获取当前日期
Date date = new Date();
//将时间格式化成yyyy-MM-dd HH:mm:ss的格式
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//创建Calendar实例
Calendar cal = Calendar.getInstance();
//设置当前时间
cal.setTime(date);
//在当前时间基础上减一年
// cal.add(Calendar.YEAR, -1);
// System.out.println(format.format(cal.getTime()));
//在当前时间基础上减一月
// cal.add(Calendar.MONTH,-1);
// System.out.println("date============="+format.format(cal.getTime()));
//同理增加一天的方法:
// cal.add(Calendar.DATE, 1);
// System.out.println(format.format(cal.getTime()));
}
@Test
public void test02(){
String s = "1322222224";
String phone = s.length() > 11 ? s.substring(0,11) : s;
System.out.println("phone"+phone);
System.out.println("phone长度 = " + phone.length());
}
}