久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      關(guān)于mysql中的時間進位問題的講解

      關(guān)于mysql中的時間進位問題的講解

      mysql更新到5.6.4 之后 , 新增了一個叫factional seconds的特性 , 可以記錄時間的毫秒值。但是目前的數(shù)據(jù)庫是不記錄毫秒值的 , 所以會產(chǎn)生一個java中時間的Milliseconds超過500就會四舍五入的問題。

      下面是一個例子,演示了時間是如何進位的。首先創(chuàng)建一張表:

      CREATE TABLE test_time (  time_sec   datetime,  time_millis datetime(3),  time_micros datetime(6),  stamp_sec  timestamp,  stamp_millis timestamp(3),  stamp_micros timestamp(6) );

      有的小伙伴可能不知道 datetime 和 timestamp 定義時是可以帶精度的,精度值為 0~6,表示保留幾位小數(shù),默認(rèn)值為 0。顯然保留 3 位可看作精度為毫秒,保留 6 位可看作精度為微秒。

      (在線學(xué)習(xí)視頻教程推薦:mysql視頻教程)

      然后我們插入一條記錄:

      INSERT INTO test_time ( time_sec, time_millis, time_micros,  stamp_sec, stamp_millis, stamp_micros ) VALUES(  '2019-11-30 12:34:56.987654',  '2019-11-30 12:34:56.987654',  '2019-11-30 12:34:56.987654',  '2019-11-30 12:34:56.987654',  '2019-11-30 12:34:56.987654',  '2019-11-30 12:34:56.987654' );

      然后再做一次 select * from test_time 查詢就能看到下面的結(jié)果:

      time_sec             |time_millis            |time_micros               |stamp_sec            |stamp_millis           |stamp_micros              | ---------------------|-----------------------|--------------------------|---------------------|-----------------------|--------------------------| 2019-11-30 12:34:57.0|2019-11-30 12:34:56.988|2019-11-30 12:34:56.987654|2019-11-30 12:34:57.0|2019-11-30 12:34:56.988|2019-11-30 12:34:56.987654|

      可以看到 time_sec 和 stamp_sec 在數(shù)據(jù)庫中的秒值都被進位了,time_millis 和 stamp_millis 的毫秒值都被進位了。

      由此可見,要避免這樣的誤差,有兩個手段:

      1、定義字段的時候使用 datetime(6) 或 timestamp(6);

      2、定義字段時不帶精度,但在將時間存入數(shù)據(jù)庫之前,要將毫秒值截取掉。

      相關(guān)文章教程推薦:mysql教程

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號