Date currentDate = Calendar.getInstance().getTime(); String formatDate = SimpleDateFormat("yyyyMMdd hh:mm:ss")).format(currentDate);
不对啊,出错啊 我是在JSP页面里写的 org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 7 in the jsp file: /insert.jsp Generated servlet error: The type Date is ambiguousAn error occurred at line: 7 in the jsp file: /insert.jsp Generated servlet error: The method SimpleDateFormat(String) is undefined for the type insert_jsp
import java.util.*; class DateTime { public static void main(String[] args) { Calendar c=Calendar.getInstance(); int year=c.get(Calendar.YEAR); int month=c.get(Calendar.MONTH)+1; int date=c.get(Calendar.DATE); String str1=year+(month<10?"0"+month:""+month)+(date<10?"0"+date:""+date); int hour=c.get(Calendar.HOUR); int minute=c.get(Calendar.MINUTE); int second=c.get(Calendar.SECOND); if(c.get(Calendar.AM_PM)==Calendar.PM) hour+=12; String str2=(hour<10?"0"+hour:""+hour)+(minute<10?":0"+minute:":"+minute)+(second<10?":0"+second:":"+second); System.out.println (str1); System.out.println (str2); } }
public static void main(String[] args) { // TODO Auto-generated method stub SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); Date d = new Date(); String strDate = sdf.format(d); System.out.println(strDate); }
String formatDate =
SimpleDateFormat("yyyyMMdd hh:mm:ss")).format(currentDate);
我是在JSP页面里写的
org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 7 in the jsp file: /insert.jsp
Generated servlet error:
The type Date is ambiguousAn error occurred at line: 7 in the jsp file: /insert.jsp
Generated servlet error:
The method SimpleDateFormat(String) is undefined for the type insert_jsp
class DateTime
{
public static void main(String[] args)
{
Calendar c=Calendar.getInstance();
int year=c.get(Calendar.YEAR);
int month=c.get(Calendar.MONTH)+1;
int date=c.get(Calendar.DATE);
String str1=year+(month<10?"0"+month:""+month)+(date<10?"0"+date:""+date);
int hour=c.get(Calendar.HOUR);
int minute=c.get(Calendar.MINUTE);
int second=c.get(Calendar.SECOND);
if(c.get(Calendar.AM_PM)==Calendar.PM)
hour+=12;
String str2=(hour<10?"0"+hour:""+hour)+(minute<10?":0"+minute:":"+minute)+(second<10?":0"+second:":"+second);
System.out.println (str1);
System.out.println (str2);
}
}
比如PB中的:string(now(),"HH:MM:SS"),string(today(),"YYYYMMDD"),就没有这样的东西吗?
// TODO Auto-generated method stub
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
Date d = new Date();
String strDate = sdf.format(d);
System.out.println(strDate);
}