标签:
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);
}
}
java中,Date数据类型和JSONObject数据类型之间的转换
标签:
原文地址:http://www.cnblogs.com/sayy/p/4882961.html