抽象类是不能被new的,是不可以创建实例的。
时间格式化类
用来把时间对象转换成字符串或者把字符串转换成时间对象
获得今天是所处年份的第几天
package Test1;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
//测试时间对象和字符串对象的互相转换
//DateFormat抽象类和SimpleDateFormat实现类的使用
public class TestDateFormat {
public static void main(String[] args) throws ParseException {
SimpleDateFormat s=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String str=s.format(new Date()); //把时间转换成字符串,因为是时间赋值给字符串
System.out.println(str);
//将字符串转成时间
SimpleDateFormat s1=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date str1=s1.parse("2020-03-18 09:28:09");
System.out.println(str1);
}
}