I managed in JAVA to store a calendar into a mysql DATETIME field To fetch this value
我在JAVA中管理将日历存储到mysql DATETIME字段中以获取此值
entry.date = Calendar.getInstance(TimeZone.getTimeZone("UT"));
entry.date.setTime(rs.getDate(DBBLogEntries.entDate));
Where the entry.date is a java.util.Calendar In the database the value is this: '2012-07-07 07:18:46' I store all date values in a unique timezone in the db. ready to make all the extra work required to add or substract hours depending on the country from wich the request is comming.
其中entry.date是java.util.Calendar在数据库中,值为:'2012-07-07 07:18:46'我将所有日期值存储在db中的唯一时区中。准备好根据请求提交的国家/地区进行添加或减少小时数所需的所有额外工作。
The problem is that it brings the date but doesn't seem to brinng me the time. Any sugestion please? Thanks in advance.
问题是它带来了日期,但似乎没有给我带来时间。有消化吗?提前致谢。
4 个解决方案
#1
2
Probably because Java has a different date format than mysql format
(YYYY-MM-DD HH:MM:SS
)
可能是因为Java的日期格式与mysql格式不同(YYYY-MM-DD HH:MM:SS)
Visit the link :
访问链接:
http://www.coderanch.com/t/304851/JDBC/java/Java-date-MySQL-date-conversion
http://www.coderanch.com/t/304851/JDBC/java/Java-date-MySQL-date-conversion
You may use SimpleDateFormat
as follows.
您可以按如下方式使用SimpleDateFormat。
java.util.Date dt = new java.util.Date();
java.text.SimpleDateFormat sdf =
new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateTime = sdf.format(dt);
#2
1
You should read a timestamp
from the ResultSet
object.
您应该从ResultSet对象中读取时间戳。
java.sql.Timestamp ts = rs.getTimestamp( DBBLogEntries.entDate );
Which returns a Timestamp
instance that includes date and time.
返回包含日期和时间的Timestamp实例。
#3
0
don't use Java.util.Date ,use the Java.sql.Date.
不要使用Java.util.Date,请使用Java.sql.Date。
#4
0
Are you using the MySql DATE type? This does not preserve the time component.
您使用的是MySql DATE类型吗?这不会保留时间组件。
http://dev.mysql.com/doc/refman/5.5/en/datetime.html
http://dev.mysql.com/doc/refman/5.5/en/datetime.html
Alternatively how are you retrieving the date from the db?
或者你如何从数据库中检索日期?
#1
2
Probably because Java has a different date format than mysql format
(YYYY-MM-DD HH:MM:SS
)
可能是因为Java的日期格式与mysql格式不同(YYYY-MM-DD HH:MM:SS)
Visit the link :
访问链接:
http://www.coderanch.com/t/304851/JDBC/java/Java-date-MySQL-date-conversion
http://www.coderanch.com/t/304851/JDBC/java/Java-date-MySQL-date-conversion
You may use SimpleDateFormat
as follows.
您可以按如下方式使用SimpleDateFormat。
java.util.Date dt = new java.util.Date();
java.text.SimpleDateFormat sdf =
new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateTime = sdf.format(dt);
#2
1
You should read a timestamp
from the ResultSet
object.
您应该从ResultSet对象中读取时间戳。
java.sql.Timestamp ts = rs.getTimestamp( DBBLogEntries.entDate );
Which returns a Timestamp
instance that includes date and time.
返回包含日期和时间的Timestamp实例。
#3
0
don't use Java.util.Date ,use the Java.sql.Date.
不要使用Java.util.Date,请使用Java.sql.Date。
#4
0
Are you using the MySql DATE type? This does not preserve the time component.
您使用的是MySql DATE类型吗?这不会保留时间组件。
http://dev.mysql.com/doc/refman/5.5/en/datetime.html
http://dev.mysql.com/doc/refman/5.5/en/datetime.html
Alternatively how are you retrieving the date from the db?
或者你如何从数据库中检索日期?