import java.text.SimpleDateFormat;
import java.util.Date;
public class DateRge{
public static void init(){
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
String str = null;
// StringתDate
str = "2007-1-18";
try {
date = format1.parse(str);
} catch (Exception e) {
e.printStackTrace();
}
//DateתString
date=new Date();
str=format1.format(date);
System.out.println(str);
}
public static void main(String[] arg){
DateRge d=new DateRge();
d.init();
}
}
java String和Date转换
最新推荐文章于 2024-09-07 04:01:09 发布