问个关于日期的问题

不善^ 2009-04-13 01:40:43
问两个关于日期的问题
1.JSP页面如何调用系统日期 最好是 显示 年 - 月 -日 (我是要让一个日期显示在一个表格里,此日期不是从数据库返回)
2.我从数据库里返回了日期并显示在页面但是只显示 年-月-日 如何在页面上显示 年-月-日-几点-几分-几秒?(此日期是从数据库返回)
...全文
152 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
mething 2009-04-23
  • 打赏
  • 举报
回复
来源:www.java21.cn这是一个jsp即时显示年月日时分秒得例子,你可以参照一下
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JS特效学院|JsWeb8.cn|---年月日时分秒的即时显示</title>

</head>

<body onload=startclock()>

<form name="clock">
<script language="JavaScript">
var timerID = null;
var timerRunning = false;
function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;}
function startclock () {
stopclock();
showtime();}
function showtime () {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = now.getYear()+"年"+(now.getMonth()+1)+"月"+now.getDate()+"日" +((hours >= 12) ? " 下午 " : " 上午 " )
timeValue += ((hours >12) ? hours -12 :hours)
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
document.clock.thetime.value = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;}
</script>
<input name="thetime" style="font-size: 9pt;color:#000000;border:1px solid #FFFFFF; ; " size="28"></form>

</body>
</html>
来源:www.java21.cn
baobao04551 2009-04-23
  • 打赏
  • 举报
回复
嗯。。从各位哪儿学点。。
SHW800 2009-04-23
  • 打赏
  • 举报
回复
做软件注册的时候也遇到过这个问题,个人感觉跟三楼的方法差不多
引用:
SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd" );
Date date=new Date();
String date1=formatter.format(date)
不善^ 2009-04-15
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 java_cxrs 的回复:]
引用 13 楼 baofengyingyinaaa 的回复:
3楼的
sql=select to_char(riqi,'yyyy-mm-dd hh24:mi:ss')......from tablename;
to_char是什么意思。没见过


同问 谁能解释下这句的意思 为什么我在MYSQL编译 是错误呢
[/Quote]
我是MYSQL数据库
不善^ 2009-04-15
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 baofengyingyinaaa 的回复:]
3楼的
sql=select to_char(riqi,'yyyy-mm-dd hh24:mi:ss')......from tablename;
to_char是什么意思。没见过
[/Quote]

同问 谁能解释下这句的意思 为什么我在MYSQL编译 是错误呢
baofengyingyinaaa 2009-04-15
  • 打赏
  • 举报
回复
to_char 是oracle数据库的一个函数。得到不同格式的日期。
sqlserver-2005下,报错,不支持。
我明白楼主的意思,就是怎么才能把数据库里的年月日取出。
我是这样做的,可能比较麻烦。就是取到数据库里的值以后,到java里面去转换。
SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd hh:mm:ss" );
//Date date=new Date();
Date d=formatter.parse(从数据库中的到得字符串日期);
String date1=formatter.format(d) ;
baofengyingyinaaa 2009-04-14
  • 打赏
  • 举报
回复
3楼的
sql=select to_char(riqi,'yyyy-mm-dd hh24:mi:ss')......from tablename;
to_char是什么意思。没见过
jianguangguo 2009-04-14
  • 打赏
  • 举报
回复
同意3楼
susoft2008 2009-04-14
  • 打赏
  • 举报
回复
dateFormat..............
Godelegant 2009-04-14
  • 打赏
  • 举报
回复
顶下三楼
skycc999 2009-04-14
  • 打赏
  • 举报
回复
3楼正解,顶起来~
gwikimo 2009-04-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 chenxinhong98 的回复:]
使用jstl标签就可以,显示格式可以自已定义
HTML code<fmt:parseDatevalue="${param.date}"var="date"pattern="yyyy-MM-dd HH:mm:ss">
[/Quote]

个人觉得在JSP页面的话这种方式比较好。
yangkaixin1226 2009-04-14
  • 打赏
  • 举报
回复
3楼的方法,可行的!之前遇到过类似的问题
feixiangclf 2009-04-14
  • 打赏
  • 举报
回复
完全同意3#!
javaboy2006 2009-04-14
  • 打赏
  • 举报
回复
可以参考一下:http://javaboy2006.javaeye.com/blog/184590
fangpengyu 2009-04-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 happydaisy1985 的回复:]
格式化日期
1、显示系统日期
SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd" );
Date date=new Date();
String date1=formatter.format(date)
2、数据库提取日期显示年-月-日-几点-几分-几秒
sql=select to_char(riqi,'yyyy-mm-dd hh24:mi:ss')......from tablename;
......................
String date1=rs.getString("riqi");
[/Quote]

这种就可以
happydaisy1985 2009-04-13
  • 打赏
  • 举报
回复
格式化日期
1、显示系统日期
SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd" );
Date date=new Date();
String date1=formatter.format(date)
2、数据库提取日期显示年-月-日-几点-几分-几秒
sql=select to_char(riqi,'yyyy-mm-dd hh24:mi:ss')......from tablename;
......................
String date1=rs.getString("riqi");
happydaisy1985 2009-04-13
  • 打赏
  • 举报
回复
格式化日期
1、显示系统日期
SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd" );
Date date=new Date();
String date1=formatter.format(date)
2、数据库提取日期显示年-月-日-几点-几分-几秒
sql=select to_char(riqi,'yyyy-mm-dd hh24:mi')......from tablename;
......................
String date1=rs.getString("riqi");

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧