2010-08-20 52 views
0

我尝试生成一个触发器,在触发器语句中,我必须设置一个十进制(17,3)类型的列,其中包含实际时间戳记或unix时间戳记的秒数,但找不到解决方案。如何在MySQL中将时间戳记存储为十进制(17,3)?

+0

我可以问你 - 为什么?为什么你需要在十进制(17,3)字段类型中存储一个4字节的整数? – 2010-08-20 09:04:18

+0

远程主机还发送必须存储在此字段中的时间戳,但远程主机的时间戳带有毫秒。 MySql类型的日期或时间戳记不能存储毫秒,这就是为什么我使用十进制(17,3)。 – Alex 2010-08-20 11:31:00

回答

0

我发现溶液

指定MySQL表的数据类型为十进制(17,3)冬眠图小数到Java类型为BigDecimal,并且用一个简单的功能:

public static Date bigDec2Date(BigDecimal tsp) { 
    Calendar cal = Calendar.getInstance(); 
    cal.setTimeInMillis(tsp.longValue()); 
    return cal.getTime(); 
} 
0

//试试这个(Java代码的)

Timestamp timestamp = new Timestamp(System.currentTimeMillis());// current time 
     String decimalTime= new SimpleDateFormat("yyyyMMddhhmmss.SSS").format(timestamp); 
     System.err.println(decimalTime); 

//在mysql中

SELECT timestamp('<decimalTime>');// eg:- 
相关问题