java 获取昨天日期
Posted 星朝
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 获取昨天日期相关的知识,希望对你有一定的参考价值。
<div class="article_title">
<span class="ico ico_type_Repost"></span>
<h1>
<span class="link_title">
<a href="https://blog.csdn.net/bsmmaoshenbo/article/details/51974255">
java 获取昨天日期 </a>
</span>
</h1>
</div>
<div class="article_manage clearfix">
<div class="article_l">
</div>
<div class="category clearfix">
<div class="bog_copyright">
</div>
<div id="article_content" class="article_content csdn-tracking-statistics" data-pid="blog" data-mod="popu_307" data-dsm="post">
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/production/htmledit_views-0a60691e80.css">
<div class="htmledit_views">
转自:http://blog.sina.com.cn/s/blog_6d416c1e01019zod.html
取昨天的日期,本想的截出来日期减一就好了。又一想不对,如果今天是一号怎么办?
现有两个办法
1:老方法
Date as = new Date(new Date().getTime()-24*60*60*1000);
SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
String time = matter1.format(as);
System.out.println(time);
取出数字型的时间 再减去24*60*60*1000,就得到昨天的时间了;
这个有点过时了!
2:Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
String yesterday = new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime());
System.out.println(yesterday);
这个方法很方便,年月日都可以随心所欲的变!
3,用apache的DateUtils( 需要 import org.apache.commons.lang.time.DateUtils;)
Date currentTime = AppUtils.getCurrentDate();
//获取昨天时间
Date backupTime=DateUtils.addDays(currentTime, -1);
4.sql 查询条件包含时间的处理方法:
select * from TBIMC1 where CREATE_DATE_<to_date( to_char(sysdate-1,‘yyyy-mm-dd‘),‘yyyy-mm-dd‘)
</div>
</div>
<div class="readall_box csdn-tracking-statistics tracking-click readall_box_nobg" data-pid="blog" data-mod="popu_596" style="display: none;">
<div class="read_more_mask"></div>
<a class="btn btn-large btn-gray-fred read_more_btn" target="_self">阅读全文</a>
</div>
<ul class="article_next_prev">
<li class="prev_article">
<span onclick="_gaq.push([‘_trackEvent‘,‘function‘, ‘onclick‘, ‘blog_articles_shangyipian‘]);location.href=‘https://blog.csdn.net/bsmmaoshenbo/article/details/51974085‘;">上一篇</span>
<a href="https://blog.csdn.net/bsmmaoshenbo/article/details/51974085" onclick="_gaq.push([‘_trackEvent‘,‘function‘, ‘onclick‘, ‘blog_articles_shangyipian‘])">The specified child already has a parent. You must call removeView() on the child‘s parent first.</a>
</li>
<li class="next_article">
<span onclick="_gaq.push([‘_trackEvent‘,‘function‘, ‘onclick‘, ‘blog_articles_xiayipian‘]);location.href=‘https://blog.csdn.net/bsmmaoshenbo/article/details/51989061‘;">下一篇</span>
<a href="https://blog.csdn.net/bsmmaoshenbo/article/details/51989061" onclick="_gaq.push([‘_trackEvent‘,‘function‘, ‘onclick‘, ‘blog_articles_xiayipian‘])">ScrollView嵌套ListView问题</a>
</li>
</ul>
<div style="clear:both; height:10px;"></div>
</div>
以上是关于java 获取昨天日期的主要内容,如果未能解决你的问题,请参考以下文章