怎样获取json数据中的正确显示时间

用json接收日期类型的时间,然后在拿出这个数据的时候,这个时间不能正常显示而是会议类似下面的对象形式出现: 

怎样才能得到正确的时间呢,为此我封装了一个方法:

public String getdate(Object date) {
		
		JSONObject jso=JSONObject.fromObject(date);
		long time = jso.getLong("time");
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		String result = simpleDateFormat.format(new Date(time));
		return result ;
	}

在拿 json类型的时间的时候,我们可以用 String类来接受,然后直接调用方法 赋值给 String 类型的数据就好了。

示例:

   String birthdate= ja.getJSONObject(0).getString("date");  // 获得时间对象
   String date=new date().getdate(birthdate);   //调用封装的方法,转化为正常显示格式
   
   System.out.println(date);  //输出正常显示时间

 

你可能感兴趣的:(JSON,数据分析)