获得昨天的日期通过code昨天、日期、code

由网友(心海,)分享简介:我用下面的code得到今天的日期。I am using the following code to get today's date.Calendar cal = Calendar.getInstance();SimpleDateFormat dateFormat = new SimpleDateFormat("...

我用下面的code得到今天的日期。

I am using the following code to get today's date.

Calendar cal = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
return dateFormat.format(cal.getTime());

但我也想yesteday的相同格式的日期。

But I also want yesteday's date in the same format.

我使用

        Calendar cal = Calendar.getInstance();
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");

    cal.add(Calendar.DATE, -1);
    return dateFormat.format(cal.getTime());

但我有一种感觉,这将失败,一旦一个月或一年的变化。我该如何解决这个问题。帮助是非常欢迎的。

but I have a feeling that this will fail once the month or year changes. How do I solve this. Help is very welcome.

推荐答案

我不'这样认为..永远的日期是什么,它​​应该得到它,减去它..并返回前一天的日期。这是什么,功能彪做

I dont' think so .. what ever the date is, it should get it and subtract it.. and return the date of day before. That is what that function is ment to do

阅读全文

相关推荐

最新文章