获得昨天的日期通过code [英] Getting yesterday's date through code

查看:133
本文介绍了获得昨天的日期通过code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的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

这篇关于获得昨天的日期通过code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆