首页IT科技java get 的快捷方法(Java get yesterday’s date)

java get 的快捷方法(Java get yesterday’s date)

时间2025-04-30 18:55:02分类IT科技浏览3458
导读:Java get yesterdays date...

Java get yesterdays date

Posted on: November 1, 2008 at 12:00 AM

This section illustrates you how to obtain the yesterdays

Java get yesterdays date

This section illustrates you how to obtain the yesterdays date.

In the given example, we simply get the current date by using the method dateFormat.format(cal.getTime()).But on subtracting one day from the calendar by using the method cal.add(Calendar.DATE, -1), the method dateFormat.format(cal.getTime()) will displayed the yesterdays date.

cal.getTime()-This method returns the Date object representing the time value of Calendar.

Here is the code of GetYesterdayDate.java

import java.text.*;

import java.sql.Date;

import java.util.Calendar;

public class GetYesterdayDate{

public static void main(String[] args) {

Calendar cal = Calendar.getInstance();

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

System.out.println("Todays date is "+dateFormat.format(cal.getTime()));

cal.add(Calendar.DATE, -1);

System.out.println("Yesterdays date was "+dateFormat.format(cal.getTime()));

}

}

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
盘古ios12完美越狱(mac版ios8.1完美越狱工具下载 盘古越狱工具mac版下载地址) vue中的渲染是什么意思(Vue|数据渲染)