java 擷取昨天日期

來源:互聯網
上載者:User

標籤:from   port   clear   今天   ada   sda   common   tail   display   

    <div class="article_title">        <span class="ico ico_type_Repost"></span>        <h1>            <span class="link_title">                <a href="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=‘51974085‘;">上一篇</span>            <a href="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=‘51989061‘;">下一篇</span>            <a href="51989061" onclick="_gaq.push([‘_trackEvent‘,‘function‘, ‘onclick‘, ‘blog_articles_xiayipian‘])">ScrollView嵌套ListView問題</a>        </li>                </ul>    <div style="clear:both; height:10px;"></div></div>

java 擷取昨天日期

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.