Android:使用HTTPClient将日期对象发布到PHP

Android:使用HTTPClient将日期对象发布到PHP,php,android,post,httpclient,Php,Android,Post,Httpclient,我正在尝试使用HTTPClient将日期对象Date Date=new Date()发布到远程PHP脚本,但似乎NameValuePair不接受除字符串以外的任何其他Java对象?如果您能指导我如何使用HTTPClient 这是我的密码 ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>(); Date date = new Date(); postParameters.add(ne

我正在尝试使用HTTPClient将日期对象
Date Date=new Date()
发布到远程PHP脚本,但似乎
NameValuePair
不接受除
字符串以外的任何其他Java对象?如果您能指导我如何使用
HTTPClient

这是我的密码

ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
Date date = new Date();
postParameters.add(new BasicNameValuePair("stringObj", "Test")); //No error
postParameters.add(new BasicNameValuePair("dateTime", date));  //Error here

try{

    String response = CustomHttpClient.executeHttpPost("http://remotewebsite/test.php", postParameters);

catch{
// ...
}
ArrayList后参数=新的ArrayList();
日期=新日期();
添加(新的BasicNameValuePair(“stringObj”、“测试”)//无误
添加(新的BasicNameValuePair(“日期时间”,日期))//这里出错
试一试{
字符串响应=CustomHttpClient.executeHttpPost(“http://remotewebsite/test.php“,后参数);
抓住{
// ...
}

将其转换为字符串。确保
date
不为空/空(我在代码中没有看到您将
date
对象与
date
类中的某些方法一起使用)

例如:

postParameters.add(new BasicNameValuePair("dateTime", new Long(date.getTime()).toString())); 

将其转换为字符串。确保
date
不为空/null(我在代码中没有看到您将
date
对象与
date
类中的某些方法一起使用)

例如:

postParameters.add(new BasicNameValuePair("dateTime", new Long(date.getTime()).toString())); 

我知道我可以将其转换为字符串。但是没有办法直接传入日期对象吗?没有,因为
bnp
构造函数只接受
值的字符串。我知道我可以将其转换为字符串。但是没有办法直接传入日期对象吗?没有,因为
bnp
构造函数只接受
v的字符串值