我正在以这种格式解码包含日期public class LocationService implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener {
private LocationRequest locationRequest;
private GoogleApiClient locationClient;
private Context tempContext = null;
public static Location mLastLocation = null;
public Handler mHandler = null;
long Id = 0;
public LocationService(Context context) {
try {
tempContext = context;
if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(tempContext) == ConnectionResult.SUCCESS) {
locationRequest = LocationRequest.create();
locationRequest.setInterval(ConstantData.ACTION_LOCATIONTIME_INTERVAL); // 2000
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationClient = new GoogleApiClient.Builder(tempContext)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).build();
if (!locationClient.isConnected() || !locationClient.isConnecting()) {
locationClient.connect();
}
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(locationRequest);
builder.setNeedBle(true);
}
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onConnected(Bundle arg0) {
// TODO Auto-generated method stub
try {
mLastLocation = getLocation();
PendingResult<Status> pendingResult = LocationServices.FusedLocationApi
.requestLocationUpdates(locationClient, locationRequest, this);
getLocation task = new getLocation();
task.execute((Void) null);
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Location getLocation() {
return LocationServices.FusedLocationApi
.getLastLocation(locationClient);
}
public void stopLocationUpdates() {
try {
if (locationClient != null && locationClient.isConnected()) {
LocationServices.FusedLocationApi.removeLocationUpdates(locationClient, this);
locationClient.disconnect();
locationClient = null;
}
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private class getLocation extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
int limit = 0, totaltry = 0;
try
{
totaltry = 10;
while (limit < totaltry) {
Thread.sleep(500);
mLastLocation = getLocation();
if (mLastLocation != null
&& mLastLocation.getAccuracy() < 50)
break;
limit++;
}
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void result) {
try
{
stopLocationUpdates();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
(例如YYYY-MM-DDThh:mm:ssTZD
)的查询字符串。
我已尝试使用以下代码进行解码,
1997-07-16T19:20:30+01:00
但是这会像这样转换查询字符串
1997-07-16T19:20:30 01:00
HttpContext.Current.Server.UrlDecode(querystring);
HttpUtility.UrlDecode(querystring);
(加号)正在替换为'+'
(空格)。
如何正确解码。如果有任何其他问题请提及。