开发者

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:-
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜