我是靠谱客的博主 腼腆小天鹅,最近开发中收集的这篇文章主要介绍计算自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天后的日期所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部