第1个回答 2011-11-09
import java.util.Calendar;
import java.util.GregorianCalendar;
public class DateTest {
private int year;
private int month;
private int day;
public DateTest() {
Calendar cal=new GregorianCalendar();
this.year=cal.get(Calendar.YEAR);
this.month=cal.get(Calendar.MONTH);
this.day=cal.get(Calendar.DAY_OF_MONTH);
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
@Override
public String toString() {
return year+"年"+ month + "月"
+day + "日";
}
}
测试主方法代码:
public class test {
public static void main(String srgs[]){
DateTest dt=new DateTest();
System.out.println(dt.toString());
}
}
第2个回答 2011-11-09
/**
* 2011-11-9,上午08:33:31
*
*/
/**
* @author <a href="liushuai.baicai@hotmail.com">Baicai</a>
*
*/
public class Date {
private String yearString;
private String monthString;
private String dayString;
/**
* @return the yearString
*/
public String getYearString() {
return yearString;
}
/**
* @param yearString the yearString to set
*/
public void setYearString(String yearString) {
this.yearString = yearString;
}
/**
* @return the monthString
*/
public String getMonthString() {
return monthString;
}
/**
* @param monthString the monthString to set
*/
public void setMonthString(String monthString) {
this.monthString = monthString;
}
/**
* @return the dayString
*/
public String getDayString() {
return dayString;
}
/**
* @param dayString the dayString to set
*/
public void setDayString(String dayString) {
this.dayString = dayString;
}
@Override
public String toString(){
return this.yearString+"年"+this.monthString+"月"+this.dayString+"日";
}
}
/**
* 2011-11-9,上午08:38:23
*
*/
/**
* @author <a href="liushuai.baicai@hotmail.com">Baicai</a>
*
*/
public class TestDate {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Date date = new Date();
date.setYearString("2011");
date.setMonthString("11");
date.setDayString("9");
System.out.println(date.toString());
}
}
第3个回答 2011-11-09
public class myData
{
private String day;
private String month;
private String year;
public String getDay()
{
return day;
}
public void setDay(String day)
{
this.day = day;
}
public String getMonth()
{
return month;
}
public void setMonth(String month)
{
this.month = month;
}
public String getYear()
{
return year;
}
public void setYear(String year)
{
this.year = year;
}
@Override
public String toString()
{
return getYear()+"年"+getMonth()+"月"+getDay()+"日";
}
public static void main(String[] args)
{
myData md = new myData();
md.setYear("2011");
md.setMonth("10");
md.setDay("1");
System.out.println(md);
}
}本回答被提问者采纳
第4个回答 2011-11-09
public class SDate
{
private int year;
private int month;
private int date;
.....set, get方法...
public String toString()
{
return “”+year+"年“+month+"月”+date+“日”
}
}