1. 程式人生 > >fastjson中日期與json之間的轉換

fastjson中日期與json之間的轉換

Date date=new Date();    
//輸出毫秒值  
System.out.println(JSON.toJSONString(date));  
//預設格式為yyyy-MM-dd HH:mm:ss    
System.out.println(JSON.toJSONString(date, SerializerFeature.WriteDateUseDateFormat));  
//根據自定義格式輸出日期   第一個引數是obj型別
System.out.println(JSON.toJSONStringWithDateFormat(date, "yyyy-MM-dd", SerializerFeature.WriteDateUseDateFormat)); 
另外在我們使用fastJson時,如果查詢出來的資料有關聯關係時,第一次查詢到關聯資料時,會顯示資料,但是第二次在查到這個關聯資料時,fastjson會引用第一個,頁面就不會顯示資料,解決方法為: