android 如何发送上一个日历数据api send?

t30tvxxf  于 2022-11-20  发布在  Android
关注(0)|答案(1)|浏览(127)

这里有三个按钮,如prev、next、today。如果你点击它们,数据应该进入包含日历数据的字符串,格式为Date. String formattedDate = df.format(c.getTime());

`prev.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
    // Perform action on click
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DATE, -1);
    System.out.println("Current time => " + c.getTime());

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    String formattedDate = df.format(c.getTime());

}
});

private void requestHomeData2() {
ApiInterface apiInterface = RestAdapter.createAPI(sharedPref.getApiUrl());
callbackCall2 = apiInterface.getDate(formattedDate,AppConfig.REST_API_KEY);

this.callbackCall2.enqueue(new Callback<Callbackdate>() {
    public void onResponse(Call<Callbackdate> call, Response<Callbackdate> response) {
        Callbackdate responseHome = response.body();
        if (responseHome == null || !responseHome.status.equals("ok")) {
            onFailRequest();
            return;
        }
        displayData2(responseHome);
        swipeProgress(false);
        lyt_main_content.setVisibility(View.VISIBLE);
    }

    public void onFailure(Call<Callbackdate> call, Throwable th) {
        Log.e("onFailure", th.getMessage());
        if (!call.isCanceled()) {
            onFailRequest();
        }
    }
});
}``

格式化日期错误如何修复此错误image

jhdbpxl9

jhdbpxl91#

使用这两行上面的错误行。

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    String formattedDate = df.format(c.getTime());

相关问题