如何从日期中删除“/”并附加网址?

时间:2018-04-24 09:55:13

标签: android date android-volley

MyActivity

myurl  private static final String url ="https://tripfareapi.herokuapp.com/flightapi/src=DEL&dest=BOM&depdate=";

使用Intent

获取值
      Bundle bundle = getIntent().getExtras();
        String from = bundle.getString("from");
        String to = bundle.getString("to");
       depaturedate = bundle.getString("departuredate");

我的网址,我希望附加原始网址,其中包含我从意图中选择的所选日期

newurl = url+depaturedate;

我的截击

  private void getdata() {
    StringRequest request = new StringRequest(newurl,new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });

    RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());

    requestQueue.add(request);

}

2 个答案:

答案 0 :(得分:1)

您可以使用SimpleDateFormat

执行此操作
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String depDate= formatter.format(depaturedate);
url += depDate;

要使用SimpleDateFormat,您必须import java.text.SimpleDateFormat;

String

departuredate = departuredate.replace("/", "");
url += departuredate;

答案 1 :(得分:1)

试试这个

depaturedate = depaturedate.replace("/", "");
newurl = url+depaturedate;