如何在 Mysql DB 中保存我的日期,在我使用的代码下方,保存位置,并重复 x 次。
但现在我需要保存日期,我尝试像代码 fragment 中显示的那样。
这是更新我的代码。
public void startGeo(View view) {
isRunning = true;
ha.postDelayed(new Runnable() {
@Override
public void run() {
StringRequest request = new StringRequest(Request.Method.POST, insertURL, new com.android.volley.Response.Listener<String>() {
@Override
public void onResponse(String response) {
}
}, new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("latitude", t_latitude.getText().toString());
parameters.put("longitude", t_longitude.getText().toString());
return parameters;
}
protected void sendLocationDataToWebsite(Location location) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getDefault());
Date date = new Date(location.getTime());
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("date", URLEncoder.encode(dateFormat.format(date), "UTF-8");
}
};
requestQueue.add(request);
Toast.makeText(MapActivity.this, "Enviado", LENGTH_LONG).show();
if (isRunning) {
ha.postDelayed(this, 10000);
}
}
}, 10000);
}
非常感谢
最佳答案
这是日期代码
private String getDateTime() {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss", Locale.getDefault());
Date date = new Date();
return dateFormat.format(date);
}
此代码用于放入请求
parameters.put("date", getDateTime());
关于java - 如何在网络请求中将日期格式化为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48086445/