You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package javabean ;
import java.text.SimpleDateFormat ; // 导入SimpleDateFormat类, 用于格式化日期
import java.util.Calendar ; // 导入Calendar类, 用于操作日期
import java.util.Date ; // 导入Date类, 用于获取当前日期和时间
public class EndTime {
// 定义一个静态方法show, 接收一个整数参数n, 表示增加的天数
public static String show ( int n ) {
Date d = new Date ( ) ; // 获取当前日期和时间
SimpleDateFormat format = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) ; // 创建日期格式化对象
String currdate = format . format ( d ) ; // 格式化当前日期
System . out . println ( "现在的日期是:" + currdate ) ; // 打印当前日期
Calendar ca = Calendar . getInstance ( ) ; // 获取日历实例
ca . add ( Calendar . DATE , n ) ; // 在当前日期基础上增加n天
d = ca . getTime ( ) ; // 获取增加天数后的日期
String enddate = format . format ( d ) ; // 格式化增加天数后的日期
return enddate ; // 返回格式化后的日期字符串
}
}