Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Java日期转换为JSON日期时间_Java_Json - Fatal编程技术网

将Java日期转换为JSON日期时间

将Java日期转换为JSON日期时间,java,json,Java,Json,您好,我有以下问题: 我需要申请一个网络服务。该请求使用REST POST方法。所以我需要发送一个JSON对象来请求我的数据 以下代码描述JSON主体: { "StartTime":"\/Date(928142400000+0200)\/", "EndTime":"\/Date(928142400000+0200)\/", "RoomTypes":[0] } 如您所见,我有两个JSON dateTime格式的字段 以下是我迄今为止的Java代码: SimpleDateF

您好,我有以下问题:

我需要申请一个网络服务。该请求使用REST POST方法。所以我需要发送一个JSON对象来请求我的数据

以下代码描述JSON主体:

{
    "StartTime":"\/Date(928142400000+0200)\/",
    "EndTime":"\/Date(928142400000+0200)\/",
    "RoomTypes":[0]
}
如您所见,我有两个JSON dateTime格式的字段

以下是我迄今为止的Java代码:

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时代以来的时间。使用诸如:
json.put(“StartTime”,“\/Date”(+pStart.getTime()+“+0200”)\/”

JSON中没有日期/时间数据格式/类型。