写一个最简单的类

wangqiang8848 2009-03-10 10:19:35
就在昨天我去达内试听课,尽管那些推荐的老师不怎么样。可是那些老师讲课不错。出了一道题,写一个myDate类,老师写了很长。又修改了很多次。最后出了一个完整的类。大家今天都写一写,看看我们能打多少分。
...全文
432 39 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
39 条回复
切换为时间正序
请发表友善的回复…
发表回复
wclszh 2009-03-19
  • 打赏
  • 举报
回复
大内的date类好久没有看到了
createWang 2009-03-15
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 hpjianhua 的回复:]
MyDate类应该主要用到下面的代码:

Java code
Calendar time=Calendar.getInstance();
year = time.get(Calendar.YEAR);
month =time.get(Calendar.MONTH);
day = time.get(Calendar.DATE);
hour=time.get(Calendar.HOUR);
minute=time.get(Calendar.MINUTE);
second=time.get(Calendar.SECOND);
[/Quote]

一直以来用的都是这种方法啊。
wanghuichp 2009-03-15
  • 打赏
  • 举报
回复
学习了
starscc 2009-03-14
  • 打赏
  • 举报
回复
//MyDate.java

public class MyDate{
private int year,month,day;
MyDate(){
this(2007,1,1);
}
MyDate(int year){
this(year,1,1);
}
MyDate(int year,int month){
this(year,month,1);
}
MyDate(int year,int month,int day){
this.year=year;
this.month=month;
this.day=day;
}
public void print(){
System.out.println("The date is:\t"+year+"-"+month+"-"+day);
}
public static void main(String[] args){
MyDate date1,date2,date3,date4;
date1=new MyDate();
date1.print();
date2=new MyDate(2008);
date2.print();
date3=new MyDate(2008,8);
date3.print();
date4=new MyDate(2008,8,8);
date4.print();
}
}
lzbang 2009-03-14
  • 打赏
  • 举报
回复
学习
weizhaozhe 2009-03-14
  • 打赏
  • 举报
回复
只是一部分啊,jdk里的源码,哈哈
weizhaozhe 2009-03-14
  • 打赏
  • 举报
回复
@Deprecated
public static long UTC(int year, int month, int date,
int hrs, int min, int sec) {
int y = year + 1900;
// month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
if (month >= 12) {
y += month / 12;
month %= 12;
} else if (month < 0) {
y += CalendarUtils.floorDivide(month, 12);
month = CalendarUtils.mod(month, 12);
}
int m = month + 1;
BaseCalendar cal = getCalendarSystem(y);
BaseCalendar.Date udate = (BaseCalendar.Date) cal.newCalendarDate(null);
udate.setNormalizedDate(y, m, date).setTimeOfDay(hrs, min, sec, 0);
udate = normalize(udate);
cal = getCalendarSystem(udate);
return cal.getTime(udate);
}

weizhaozhe 2009-03-14
  • 打赏
  • 举报
回复
import java.text.DateFormat;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.lang.ref.SoftReference;
import sun.util.calendar.BaseCalendar;
import sun.util.calendar.CalendarDate;
import sun.util.calendar.CalendarSystem;
import sun.util.calendar.CalendarUtils;
import sun.util.calendar.Era;
import sun.util.calendar.Gregorian;
import sun.util.calendar.ZoneInfo;

public class Date
implements java.io.Serializable, Cloneable, Comparable<Date>
{
private static final BaseCalendar gcal =
CalendarSystem.getGregorianCalendar();
private static BaseCalendar jcal;

private transient long fastTime;


private transient BaseCalendar.Date cdate;


private static int defaultCenturyStart;


private static final long serialVersionUID = 7523967970034938905L;


public Date() {
this(System.currentTimeMillis());
}

/**
* Allocates a <code>Date</code> object and initializes it to
* represent the specified number of milliseconds since the
* standard base time known as "the epoch", namely January 1,
* 1970, 00:00:00 GMT.
*
* @param date the milliseconds since January 1, 1970, 00:00:00 GMT.
* @see java.lang.System#currentTimeMillis()
*/
public Date(long date) {
fastTime = date;
}


@Deprecated
public Date(int year, int month, int date) {
this(year, month, date, 0, 0, 0);
}

@Deprecated
public Date(int year, int month, int date, int hrs, int min) {
this(year, month, date, hrs, min, 0);
}


@Deprecated
public Date(int year, int month, int date, int hrs, int min, int sec) {
int y = year + 1900;

if (month >= 12) {
y += month / 12;
month %= 12;
} else if (month < 0) {
y += CalendarUtils.floorDivide(month, 12);
month = CalendarUtils.mod(month, 12);
}
BaseCalendar cal = getCalendarSystem(y);
cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef());
cdate.setNormalizedDate(y, month + 1, date).setTimeOfDay(hrs, min, sec, 0);
getTimeImpl();
cdate = null;
}


@Deprecated
public Date(String s) {
this(parse(s));
}


public Object clone() {
Date d = null;
try {
d = (Date)super.clone();
if (cdate != null) {
d.cdate = (BaseCalendar.Date) cdate.clone();
}
} catch (CloneNotSupportedException e) {} // Won't happen
return d;
}
wangqiang8848 2009-03-12
  • 打赏
  • 举报
回复
写代码一定给分。大家看一看我写的怎么样,给个评价
finingphon 2009-03-12
  • 打赏
  • 举报
回复
向15楼学习。
KAKUKYOWU 2009-03-12
  • 打赏
  • 举报
回复
呵呵,挺热闹留个脚印。。。
huangan0301 2009-03-12
  • 打赏
  • 举报
回复
以前也写过~~15楼的写的很不错~~
Julykey 2009-03-12
  • 打赏
  • 举报
回复
15楼很不错
cwjieNo1 2009-03-12
  • 打赏
  • 举报
回复
15搂,真强·
qiugongz 2009-03-12
  • 打赏
  • 举报
回复
以我现在的水平,15楼叹为观止!
  • 打赏
  • 举报
回复
去看看软件测试类的书吧 这种例子很多的
fortin1001 2009-03-12
  • 打赏
  • 举报
回复
路过
只要把需求考虑清楚了,类不难写吧。
那老师修改很多次的原因,估计要吗就是演示下写的过程,要吗就是他自己也没想明白。
chenchuanbo 2009-03-12
  • 打赏
  • 举报
回复
学习
timmf 2009-03-12
  • 打赏
  • 举报
回复
mark
lzc_hacker 2009-03-12
  • 打赏
  • 举报
回复
拜访学习.
加载更多回复(18)

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧