import java.text.SimpleDateFormat;
import java.util.Date;
import net.sf.json.JSONObject;
public class DateTest {
public static void main(String[] args) {
Date d = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String str= dateFormat.format(d);//将date类型转换为string类型:2015-10-15 05:00:53
System.out.println(str);
//{"date":15,"day":4,"hours":17,"minutes":3,"month":9,"seconds":12,"time":1444899792796,"timezoneOffset":-480,"year":115}
JSONObject a = JSONObject.fromObject(d);//将date类型转换为jsonObject数据类型
System.out.println(a);
Date b = new Date();
b=(Date) JSONObject.toBean(a, Date.class);//将jsonObject类型转换为date数据类型
System.out.println(b);
}
}
时间: 2024-12-24 08:50:44