java现实特定时间_如何使用Java显示指定日期?

已给出如图所示程序。但是要将程序改动为显示格式为“Jan26,1985”,然后在Mainmethod的dateclass中建立一个新的Object,MyDate然后使程序显示日期Jan31,2015。publicclassDate{prote...

已给出如图所示程序。但是要将程序改动为显示格式为“Jan 26, 1985”,然后在Main method的date class中建立一个新的Object,My Date然后使程序显示日期 Jan 31, 2015。

public class Date {

protected int year;

protected int month;

protected int day;

public static final int MINYEAR = 1583;

//Constructor

public Date(int newMonth, int newDay, int newYear){

month = newMonth;

day = newDay;

year = newYear;

}

//Observers

public int getYear(){

return year;

}

public int getMonth(){

return month;

}

public int getDay(){

return day;

}

public int lilian(){

// Returns the Lilian Day Number of this date.

// Algorithm goes here.

// See Lilian Day Numbers feature section for details.

final int Subdays = 578100;

int numDays = 0;

numDays = year * 365;

if (month <= 2)

numDays = numDays + (month - 1) * 31;

else

numDays = numDays + ((month - 1)* 31)

-((4 * (month - 1) + 27) / 10);

numDays = numDays + day;

numDays = numDays + day;

numDays = numDays + (year / 4) - (year / 100) + (year / 400);

if (month < 3){

if ((year % 4) == 0) numDays = numDays - 1;

if ((year % 100) == 0) numDays = numDays + 1;

if ((year % 400) == 0) numDays = numDays -1;

}

numDays = numDays - Subdays;

return numDays;

}

public String toString(){

//Returns this date as a String

return(month + "/" + day + "/" + year);

}

}

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值