java输入日期输出后一天
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java输入日期输出后一天相关的知识,希望对你有一定的参考价值。
package com;import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
public class Test
public static void main(String[] args)
try
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
System.out.println("请输入日期。如2017-11-01");
Scanner scan = new Scanner(System.in);
String read = scan.nextLine();
Date date = formatter.parse(read);
System.out.println("退后一天日期为:" + formatter.format(addDateOneDay(date)));
catch (ParseException e)
// TODO Auto-generated catch block
// e.printStackTrace();
System.out.println("录入错误,程序结束!");
public static Date addDateOneDay(Date date)
if (null == date)
return date;
Calendar c = Calendar.getInstance();
c.setTime(date); // 设置当前日期
c.add(Calendar.DATE, 1); // 日期加1天
date = c.getTime();
return date;
参考技术A public class MyTest
public static void main(String[] args)
Date date = getDayDate(new Date(), 2);
System.out.println(new SimpleDateFormat("yyyy年MM月dd日").format(date));
private static Date getDayDate(Date date, int i)
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, i);
return calendar.getTime();
PHP前一天,后一天,日期问题
date_default_timezone_set(‘PRC‘); //默认时区
echo "今天:",date("Y-m-d",time()),"<br>";
echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"<br>";
echo "昨天:",date("Y-m-d",strtotime("-1 day")), "<br>";
echo "明天:",date("Y-m-d",strtotime("+1 day")), "<br>";
echo "一周后:",date("Y-m-d",strtotime("+1 week")), "<br>";
echo "一周零两天四小时两秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "<br>";
echo "下个星期四:",date("Y-m-d",strtotime("next Thursday")), "<br>";
echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."<br>";
echo "一个月前:".date("Y-m-d",strtotime("last month"))."<br>";
echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."<br>";
echo "十年后:".date("Y-m-d",strtotime("+10 year"))."<br>";
以上是关于java输入日期输出后一天的主要内容,如果未能解决你的问题,请参考以下文章