How to store the timestamp as decimal(17,3) in mysql?
I try to generate a trigger, in the 开发者_开发知识库trigger statement I have to set a column of type decimal(17,3) with the actual timestamp or the seconds of unix timestamp, but could not find a solution.
I found the solution
specify the datatype in the mysql table as decimal(17,3) hibernate map decimal to the Java type BigDecimal, and the with a simple function:
public static Date bigDec2Date(BigDecimal tsp) {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(tsp.longValue());
return cal.getTime();
}
Try this (Java Code)
Timestamp timestamp = new Timestamp(System.currentTimeMillis());// current time
String decimalTime= new SimpleDateFormat("yyyyMMddhhmmss.SSS").format(timestamp);
System.err.println(decimalTime);
And in MySQL:
SELECT timestamp('<decimalTime>');// eg:-
精彩评论