[英]Converting Java Date to JSON DateTime
嗨,我有以下问题:
我需要请求一个Web服务。 请求是使用REST POST方法。 所以我需要发送一个JSON对象来请求我的数据。
以下代码描述了JSON正文:
{
"StartTime":"\/Date(928142400000+0200)\/",
"EndTime":"\/Date(928142400000+0200)\/",
"RoomTypes":[0]
}
如你所见,我有两个JSON dateTime格式的字段。
这是我的Java代码sofar:
SimpleDateFormat pSdf = new SimpleDateFormat("yyyy-mm-dd HH:mm");
Date pStart = null;
Date pEnd = null;
try{
//now i parse my strings into the Java.Date objects
pStart = pSdf.parse(sDate + " " + sStartTime);
pEnd = pSdf.parse(sDate + " " + sEndTime);
}catch (ParseException e1){
e1.PrintStackTrace();
}
//Now Building the JSON Request Object
JSONObject json = new JSONObject();
json.put("StartTime", ?); //Here i need the JSON dateTime format right?
json.put("EndTime", ?);
任何提示如何实现这一目标?
谢谢!
看起来REST服务期待自Unix时代以来的时间。 使用Date.getTime()如: json.put("StartTime", "\\/Date(" + pStart.getTime() + "+0200)\\/");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.