获取数据库当前时间并格式化

  • Post author:
  • Post category:其他


public static String  getnowtime(){


getConnect();

Date time=new Date();

try {


pstmt = conn.prepareStatement(“select now()”);

rs = pstmt.executeQuery();

if (rs.next()) {

//time=rs.getString(1);

time=rs.getTimestamp(1);

}

} catch (SQLException e) {


// TODO Auto-generated catch block

e.printStackTrace();

}

DateFormat sdf=new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);

return sdf.format(time);

}

转载于:https://my.oschina.net/kushyo/blog/752271