我是靠谱客的博主 腼腆小天鹅,这篇文章主要介绍计算自2000年1月1日起,N天后的日期,现在分享给大家,希望可以做个参考。

/**
* calculate the date from 2000-1-1 after a number of days
*/
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class TwoThousandDate {
public void getCurrentDate(int dump,DateReturn date){
Calendar ca=Calendar.getInstance();
ca.set(Calendar.YEAR,2000);
ca.set(Calendar.MONTH, Calendar.JANUARY);
ca.set(Calendar.DAY_OF_MONTH,1);
ca.add(Calendar.DAY_OF_MONTH, dump);
// SimpleDateFormat define the new date format。
SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd");
//构造任意格式
String time = sm.format(ca.getTime());
String[] timeArray= time.split("-");
date.setYear(Integer.parseInt(timeArray[0]));
date.setMonth(Integer.parseInt(timeArray[1]));
date.setDay(Integer.parseInt(timeArray[2]));
}
public static void main(String[] args){
TwoThousandDate twoThousandDate = new TwoThousandDate();
DateReturn date = new DateReturn();
twoThousandDate.getCurrentDate(10,date);
System.out.println(date.getCurrentDate());
}
}
class DateReturn{
private int year;
private int month;
private int day;
public void setYear(int year){
this.year = year;
}
public void setMonth(int month){
this.month = month;
}
public void setDay(int day){
this.day = day;
}
public String getCurrentDate(){
return this.year + "-" + this.month + "-" + this.day;
}
}

最后

以上就是腼腆小天鹅最近收集整理的关于计算自2000年1月1日起,N天后的日期的全部内容,更多相关计算自2000年1月1日起,N天后内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(96)

评论列表共有 0 条评论

立即
投稿
返回
顶部