JSP中取得当前的日期和时间分别怎么取的啊?

luoxxhh 2001-08-17 09:02:56
...全文
426 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
redstarstar 2001-08-22
哈,Java API上的例子,大家用哪使哪就成了。:)
回复
packy_li 2001-08-22
同意redstarstar(红星星),方法可行。只是列出得太多了点,你知需要把这写为一个类,然后在jsp中像调用JavaBean一样调用就行了! 
回复
dragonerfish 2001-08-21
关注!!!
回复
lci21 2001-08-17
如果想取日期和时间,可以利用substring()方法!
例如:取日期
String ddate=cdate.substring(0,10);
取时间自己来吧!
呵呵
回复
ciyun 2001-08-17
java.util.Date dat = new java.util.Date();
String datetime=new Timestamp(dat.getTime()).toString();
回复
lci21 2001-08-17
按下面的方式取:
import java.text.*;
import java.util.*;

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//定制时间格式:(2001-08-17 9:45:23)
String cdate = format(new Date());//取的当前日期和时间
回复
Date d=new Date ();
String gTime=String.valueOf (d.getYear()+1900)+"-"+String.valueOf (d.getMonth()+1)+"-"+String.valueOf (d.getDate())+ " " +String.valueOf (d.getHours ())+":"+String.valueOf (d.getMinutes ())+":"+String.valueOf (d.getSeconds());
回复
whxab 2001-08-17
<%@ page import="java.util.*"%>
<%Calendar thisMonth=Calendar.getInstance();
year=thisMonth.get(Calendar.YEAR);
month=thisMonth.get(Calendar.MONTH)+1;
day=thisMonth.get(Calendar.DAY_OF_MONTH);
hour=thisMonth.get(Calendar.HOUR);
minute=thisMonth.get(Calendar.MINUTE);
sencond=thisMonth.get(Calendar.SECOND);%>
回复
redstarstar 2001-08-17
用Calendar类

import java.util.Calendar;

public class newtime
{
public static void main(String[] args)
{
Calendar calendar = Calendar.getInstance();
System.out.println("Current Time");
System.out.println("ERA: " + calendar.get(Calendar.ERA));
System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
System.out.println("DATE: " + calendar.get(Calendar.DATE));
System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
System.out.println("DAY_OF_WEEK_IN_MONTH: "+ calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
System.out.println("ZONE_OFFSET: "+ (calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000)));
System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET)/(60*60*1000)));
System.out.println("Current Time, with hour reset to 3");
System.out.println("ERA: " + calendar.get(Calendar.ERA));
System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
System.out.println("DATE: " + calendar.get(Calendar.DATE));
System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
System.out.println("DAY_OF_WEEK_IN_MONTH: "+ calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
System.out.println("ZONE_OFFSET: "+ (calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000))); // in hours
System.out.println("DST_OFFSET: "+ (calendar.get(Calendar.DST_OFFSET)/(60*60*1000))); // in hours
}
}
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2001-08-17 09:02
社区公告
暂无公告