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);
}
}

相关文章:

  • 2021-12-05
  • 2021-12-04
  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
猜你喜欢
  • 2021-06-21
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2022-01-28
相关资源
相似解决方案