Mysql数据库中的时间精确到秒,取出数据时想要精确到日

format(new Date()); //当前时间,换成数据库的时间就行了 如果要在jsp页面,就用 就ok了注意引入fmt: ...
Mysql数据库中的时间精确到秒,取出数据时想要精确到日
使用SimpleDateFormat
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String date = format.format(你从数据库拿到的date);2015-12-07
在java也页面:
SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy/MM/dd "); //时间格式化的格式
String nowTimeStr = sDateFormat.format(new Date()); //当前时间,换成数据库的时间就行了
如果要在jsp页面,就用
<fmt:formatDate value="你的时间" pattern="yyyy-MM-dd" type="date" dateStyle="long" />就ok了注意引入fmt:<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>2015-12-07
SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-mm-dd");
使用这个类,可以格式化时间,这里的规则是格式化到年月日,格式如括号参数写的
具体参考,http://blog.csdn.net/gubaohua/article/details/5754882015-12-07
java里面传正常的Date格式
mysql语句:select * from test where to_days(test_date) = to_days('时间参数');2017-08-31
mengvlog 阅读 46 次 更新于 2025-10-31 08:49:23 我来答关注问题0
檬味博客在线解答立即免费咨询

mySQL相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部