jsp中获得SQL SERVER详细的时间

来源:互联网 发布:java ssh源码 编辑:程序博客网 时间:2024/05/29 13:25
          最近在做BBS时遇到要从SQL SERVER中读取数据库的具体时间,包括时,分,秒.我试了几次发现用getDate(..)返回格式化后时分秒都是0,后来用getTime(..)发现格式化后年月日都是1997....于是就用下面的方法分两次取得年月日和时分秒:
         
          
public static String getTime(Date date)  {
        String temp 
= new SimpleDateFormat("yyyy-MM-dd ",
                Locale.SIMPLIFIED_CHINESE).format(date);
        
return temp;
           }

    
        
传进来getTime()获得的结果,取得时分秒*/
          
public static String getMoreTime(Date date)  {
        String temp 
= new SimpleDateFormat("HH:mm:ss",
                Locale.SIMPLIFIED_CHINESE).format(date);
        
return temp;
         }

getTime(rs.getDate("timeindex"))  + getMoreTime(rs.getTime("timeindex"))  就可以获得具体的时间.不知道大家有没有更好的方法?

原创粉丝点击