Я создаю приложение, которое вызывает API через залп
API: http://cricapi.com/api/matches?apikey=<my API key>
После вызова этого API я получаю все данные сегодня и после. Мой вопрос, я хочу получать только данные текущей даты (Сегодня).
MainActivity.java
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private RecyclerView.Adapter adapter;
private List<Model> modelList;
private String url = "http://cricapi.com/api/matches?apikey=<key>";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = findViewById(R.id.recyclerview);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
modelList = new ArrayList<>();
loadUrlData();
}
private void loadUrlData() {
final ProgressDialog pd = new ProgressDialog(this);
pd.setMessage("Loading ...");
pd.show();
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
pd.dismiss();
try {
JSONArray jsonArray=new JSONObject(response).getJSONArray("matches");
for (int i=0; i<jsonArray.length(); i++){
try {
String uniqueid=jsonArray.getJSONObject(i).getString("unique_id");
String team1=jsonArray.getJSONObject(i).getString("team-1");
String team2=jsonArray.getJSONObject(i).getString("team-2");
String matchType=jsonArray.getJSONObject(i).getString("type");
String matchStatus=jsonArray.getJSONObject(i).getString("matchStarted");
if (matchStatus.equals("true")){
matchStatus="Match Started";
}else {
matchStatus="Match not started";
}
String dateTimeGMT=jsonArray.getJSONObject(i).getString("dateTimeGMT");
SimpleDateFormat format1=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
format1.setTimeZone(TimeZone.getTimeZone(dateTimeGMT));
Date date=format1.parse(dateTimeGMT);
SimpleDateFormat format2=new SimpleDateFormat("yyyy-MM-dd HH:mm");
format2.setTimeZone(TimeZone.getTimeZone("GMT"));
String dateTime=format2.format(date);
Model model=new Model(uniqueid,team1,team2,matchType,matchStatus,dateTime);
modelList.add(model);
}catch (Exception e){
Toast.makeText(MainActivity.this,"" +e.getMessage(),Toast.LENGTH_SHORT).show();
}
}
adapter=new MyAdapter(modelList,getApplicationContext());
recyclerView.setAdapter(adapter);
}catch (Exception e){
Toast.makeText(MainActivity.this,"" +e.getMessage(),Toast.LENGTH_SHORT).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this,"Error:" +error,Toast.LENGTH_LONG).show();
}
});
RequestQueue requestQueue= Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
}