注册 登录
编程论坛 J2EE论坛

JSP 怎么获取当前时间

qxhan1128 发布于 2006-08-07 09:23, 2392 次点击

先获取当前时间再转换为年、月、日
比如:获得当前时间2006-8-7 10:22:56
年2006
月8
日7

那位兄弟看下这个函数怎么写?

[此贴子已经被作者于2006-8-7 9:30:13编辑过]

7 回复
#2
球球2006-08-07 09:46
GregorianCalendar gc=new GregorianCalendar();
String now=gc.get(Calendar.YEAR)+"年"+(gc.get(Calendar.MONTH)+1)+"月"+gc.get(Calendar.DATE)+"日";
System.out.println("当前时间:"+now);
#3
qxhan11282006-08-07 10:00
TKS,年月日OK了。
时间显示为2006-8-7 10:22:56怎么写?
#4
qxhan11282006-08-07 10:06

将指定的时间转换为年月日格式怎么转换。
比如时间(2006-08-07 12:59:59)进行转换。

#5
刘敬2006-08-08 15:40

偶来为你解决
import java.util.*;
import java.text.*;
public class test{
public static void main(String args[]) {
Date today=new Date();
SimpleDateFormat f=new SimpleDateFormat("yyyy年MM月dd日 hh:mm:ss");
String time=f.format(today);
System.out.println(time);
}
}
格式里的时如果用hh表示用12小时制,HH表示用24小时制。
输出结果如下:
2006年08月08日 07:22:10
改成 SimpleDateFormat f = new SimpleDateFormat("yyyy:mm:dd hh:mm:ss");输出结果当然是
2006:08:08 07:22:10

#6
xiuyuan1232006-10-24 14:26

//SYSTEM_TIME
public Date getSystemTime() throws Exception
{
dbEngine dbengine = new dbEngine();
Date system_time = new Date();
Connection connection = dbengine.getConnection();
String sql="SELECT CONVERT(char(10),getdate(),20) AS SYSTEM_TIME";
Statement statement = connection.createStatement();
// 执行SQL 语句得到结果集合
ResultSet result = statement.executeQuery(sql);
while(result.next())
{
system_time = result.getDate(1);
}
// String system_time= "";
return system_time;

}

#7
lengxin2006-10-25 14:19
<%=new java.util.Date().toLoacaleString()%>
#8
北极光2006-10-30 15:50
用sql直接从dual表中取不就得了
1