如何在JSP页面中获取当前系统时间
请教:如何在JSP页面中获取当前系统时间,只需要获取年,月,日就可以了
谢谢
------解决方案--------------------试试
<%
java.util.Date now=new java.util.Date();
out.println(now);
%>
如果只要年月日,可以用subString()截取.
或者用这个 String time=new SimpleDateFormat( "yyyy-MM-dd ").format(Calendar.getInstance().getTime);
------解决方案--------------------Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd ");
String dateString = formatter.format(currentTime);
dataString 的格式就是2007-03-08这类型
------解决方案--------------------学习ing
------解决方案--------------------2楼和3楼的是对的
------解决方案-------------------- <script language= "javascript ">
var today=new Date()
var month=today.getMonth()+1
document.write(today.getYear()+ "年 "+month+ "月 "+today.getDate()+ "日 ")
</script>
------解决方案--------------------mark
------解决方案-------------------- <%=(new java.util.Date()).toLocaleString()%>
这段代码可以显示当前的时间
------解决方案--------------------方法很多我给你说三种我喜欢的方法吧
1:
import java.util.*;
int y,m,d,h,mm;
Calendar c = Calendar.getInstance();
y = c.get(Calendar.YEAR); //年
m = c.get(Calendar.MONTH) + 1; //月
d = c.get(Calendar.DAY_OF_MONTH); //日
h = c.get(Calendar.HOUR); //时
mm = c.get(Calendar.MINUTE); //分
2:
java.util.Date d = new java.util.Date();
java.text.SimpleDateFormat dformat = new java.text.SimpleDateFormat( "yyyy-MM-dd ");
String datetime = dformat.format(d);
System.out.println(datetime);
3:
import java.util.*;
import java.text.*;
Date now = new Date();
DateFormat defaultFormat = DateFormat.getDateInstance();
DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT);
DateFormat mediumFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
DateFormat longFormat = DateFormat.getDateInstance(DateFormat.LONG);
DateFormat fullFormat = DateFormat.getDateInstance(DateFormat.FULL);
String defaultDate = defaultFormat.format(now);
String shortDate = shortFormat.format(now);
String mediumDate = mediumFormat.format(now);
String longDate = longFormat.format(now);
String fullDate = fullFormat.format(now);
System.out.println( "(Default) Today : " + defaultDate);
System.out.println( "(SHORT) Today : " + shortDate);
System.out.println( "(MEDIUM) Today : " + mediumDate);
System.out.println( "(LONG) Today : " + longDate);
System.out.println( "(FULL) Today : " + fullDate);