如何取得服务器的时间(0分)

  • 主题发起人 主题发起人 laskes
  • 开始时间 开始时间
L

laskes

Unregistered / Unconfirmed
GUEST, unregistred user!
请问如何用Jsp语句怎么写读取服务器的时间?
 
以前某个富翁的例子:
转贴一下:
<%@ page import ="java.util.*,java.*" %>
<h1>一个可以取毫秒的精确时间的例子 </h1>
int year,month,day,hour,minute,second,millisecond,dayweek;
Calendar nowDate = Calendar.getInstance();
StringBuffer strDate = new StringBuffer();
year = nowDate.get(Calendar.YEAR);
month = nowDate.get(Calendar.MONTH)+1;
day = nowDate.get(Calendar.DAY_OF_MONTH);
hour = nowDate.get(Calendar.HOUR);
minute = nowDate.get(Calendar.MINUTE);
second = nowDate.get(Calendar.SECOND);
millisecond = nowDate.get(Calendar.MILLISECOND);
dayweek=nowDate.get(Calendar.DAY_OF_WEEK);
strDate.append(year+"年");
if (month>9)
strDate.append(month+"月");
else
strDate.append("0"+month+"月");
if (day>9)
strDate.append(day+"日");
else
strDate.append("0"+day+"日");
if (hour>9)
strDate.append(hour+"时");
else
strDate.append("0"+hour+"时");
if (minute>9)
strDate.append(minute+"分");
else
strDate.append("0"+minute+"分");
if (second>9)
strDate.append(second+"秒");
else
strDate.append("0"+second+"秒");
strDate.append(millisecond+"毫秒");
out.println("当前时间为:"+strDate);
或者:
long nowtime = new Date().getTime();
out.println(nowtime);
 
Date newDate = new Date();
int year = newDate.getYear();
int month= newDate.getMonth()+1;
int day = newDate.getDay();
 
如果是SQLServer服务器:select getdate()
 
Oracle:select sysdate from dual;
 
后退
顶部