当前位置: 技术问答>java相关
怎样取得当前的系统日期呀?用Date thedate = new Date();不行。
来源: 互联网 发布时间:2017-03-29
本文导语: 我要在JSP里取得当前的系统日期,程序如下: Date thedate = new Date(); 运行时提示:No constructor matching Date() found in class java.sql.Date. 另外:要取得当前日期的年、月和日, theyear = thedate.getyear(); themonth = thedate.ge...
我要在JSP里取得当前的系统日期,程序如下:
Date thedate = new Date();
运行时提示:No constructor matching Date() found in class java.sql.Date.
另外:要取得当前日期的年、月和日,
theyear = thedate.getyear();
themonth = thedate.getmonth();
theday = thedate.getday();
其中的变量:theyear,themonth,theday应声明为何种类型?
Date thedate = new Date();
运行时提示:No constructor matching Date() found in class java.sql.Date.
另外:要取得当前日期的年、月和日,
theyear = thedate.getyear();
themonth = thedate.getmonth();
theday = thedate.getday();
其中的变量:theyear,themonth,theday应声明为何种类型?
|
Calendar cal = Calendar.getInstance();
int iyear = cal.get(Calendar.YEAR );
int imonth=cal.get(Calendar.MONTH );
int iday=cal.get(Calendar.DATE);
String stryear = Integer.toString(iyear);
String strmonth=Integer.toString(imonth);
String strday=Integer.toString(iday);
int iyear = cal.get(Calendar.YEAR );
int imonth=cal.get(Calendar.MONTH );
int iday=cal.get(Calendar.DATE);
String stryear = Integer.toString(iyear);
String strmonth=Integer.toString(imonth);
String strday=Integer.toString(iday);
|
public String getEe()//计算当前时间用Date类
{
Date cur_date=new Date();
int year=cur_date.getYear()+1900;
int month=cur_date.getMonth()+1;
int day=cur_date.getDate();
int hour=cur_date.getHours();
int minutes=cur_date.getMinutes();
int second=cur_date.getSeconds();
ee=Integer.toString(year)+"-"+Integer.toString(month)+"-"+Integer.toString(day)+" "+Integer.toString(hour)+":"+Integer.toString(minutes)+":"+Integer.toString(second);
return ee;
}
public String getFf()//日期数据的定制格式用SimpleDateFormat类
{
SimpleDateFormat fdata=new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
Date cur_date=new Date();
ff=fdata.format(cur_date);
return ff;
}
public String getHh()//日期数据的定制格式用DateFormat类
{
Date now=new Date();
DateFormat fdate=DateFormat.getDateInstance();
hh=fdate.format(now);
return hh;
}
{
Date cur_date=new Date();
int year=cur_date.getYear()+1900;
int month=cur_date.getMonth()+1;
int day=cur_date.getDate();
int hour=cur_date.getHours();
int minutes=cur_date.getMinutes();
int second=cur_date.getSeconds();
ee=Integer.toString(year)+"-"+Integer.toString(month)+"-"+Integer.toString(day)+" "+Integer.toString(hour)+":"+Integer.toString(minutes)+":"+Integer.toString(second);
return ee;
}
public String getFf()//日期数据的定制格式用SimpleDateFormat类
{
SimpleDateFormat fdata=new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
Date cur_date=new Date();
ff=fdata.format(cur_date);
return ff;
}
public String getHh()//日期数据的定制格式用DateFormat类
{
Date now=new Date();
DateFormat fdate=DateFormat.getDateInstance();
hh=fdate.format(now);
return hh;
}