网站首页 新闻首页 网页设计图形动画软件编程网站开发办公软件操作系统数据库网络技术认证考试范文资料黑客攻防 书籍教程 进入论坛

取时间的小类

http://www.diybl.com/ 2007-2-6  网络 点击:  [ 评论 ]
文章搜索:    【点击打包该文章】

package pub.dates;
import java.text.DateFormat;
import java.util.*;

public class Dates
{
Date param=null;
Calendar ca=Calendar.getInstance();
public Dates()
{
  param=new Date();
  ca.setTime(param);
}
public Dates(Date vars)
{
  param=vars;
  ca.setTime(param);
}
public Dates(int y,int m,int d)
{
  y=y-1900;m=m-1;
  param=new Date(y,m,d);
  ca.setTime(param);
}
//
public int getYear()
{
  return ca.get(Calendar.YEAR);
}
public int getMonth()
{
  return 1+ca.get(Calendar.MONTH);
}
public int getDay()
{
  return ca.get(Calendar.DAY_OF_MONTH);
}
public int getHour()
{
  return ca.get(Calendar.HOUR_OF_DAY);
}
    
public int getMinute()
{
  return ca.get(Calendar.MINUTE);
}

public int getSecond()
{
  return ca.get(Calendar.SECOND);
}
public String getDate()
{
  return getYear()+"-"+getMonth()+"-"+getDay();
}

public String getTime()
{
  return getHour() + ":" + getMinute() + ":" + getSecond();
}
}
//package部分自己随意.
构造方法:(3个)
Dates();
Dates(Date date);
Dates(int y,int m, int d); y,m,d是年.月.日

方法:
getYear();  getMonth();  getDay(); getHour();  getMinute(); getSecond(); getDate(); getTime()

如果图片或页面不能正常显示请点击这里 站内搜索:   

文章评论

请您留言

 

最新新闻