• <i id='6xyGD'><tr id='6xyGD'><dt id='6xyGD'><q id='6xyGD'><span id='6xyGD'><b id='6xyGD'><form id='6xyGD'><ins id='6xyGD'></ins><ul id='6xyGD'></ul><sub id='6xyGD'></sub></form><legend id='6xyGD'></legend><bdo id='6xyGD'><pre id='6xyGD'><center id='6xyGD'></center></pre></bdo></b><th id='6xyGD'></th></span></q></dt></tr></i><div id='6xyGD'><tfoot id='6xyGD'></tfoot><dl id='6xyGD'><fieldset id='6xyGD'></fieldset></dl></div>

      <small id='6xyGD'></small><noframes id='6xyGD'>

    1. <tfoot id='6xyGD'></tfoot>
          <bdo id='6xyGD'></bdo><ul id='6xyGD'></ul>
      1. <legend id='6xyGD'><style id='6xyGD'><dir id='6xyGD'><q id='6xyGD'></q></dir></style></legend>

        Hibernate 在读取 Java 日历对象并将其写入 SQL TIME

        时间:2023-07-25
        <legend id='XvScl'><style id='XvScl'><dir id='XvScl'><q id='XvScl'></q></dir></style></legend>
            <bdo id='XvScl'></bdo><ul id='XvScl'></ul>

          • <small id='XvScl'></small><noframes id='XvScl'>

              <tbody id='XvScl'></tbody>

              <tfoot id='XvScl'></tfoot>

                <i id='XvScl'><tr id='XvScl'><dt id='XvScl'><q id='XvScl'><span id='XvScl'><b id='XvScl'><form id='XvScl'><ins id='XvScl'></ins><ul id='XvScl'></ul><sub id='XvScl'></sub></form><legend id='XvScl'></legend><bdo id='XvScl'><pre id='XvScl'><center id='XvScl'></center></pre></bdo></b><th id='XvScl'></th></span></q></dt></tr></i><div id='XvScl'><tfoot id='XvScl'></tfoot><dl id='XvScl'><fieldset id='XvScl'></fieldset></dl></div>

                • 本文介绍了Hibernate 在读取 Java 日历对象并将其写入 SQL TIMESTAMP 时使用哪个时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  当 Hibernate Java Calendar 对象到 SQL TIMESTAMP 列,它调整到哪个时区日期,计算机的日期或日历对象(或其他)中指定的日期?

                  When Hibernate writes a Java Calendar object to an SQL TIMESTAMP column, to which time zone does it adjust the date, that of the computer or that specified in the calendar object (or some other)?

                  当 Hibernate 读取 TIMESTAMP 到日历对象中时,它将日期转换到哪个时区?

                  When Hibernate reads the TIMESTAMP into the calendar object, to which time zone does it translate the date?

                  推荐答案

                  当 Hibernate 将 Java 日历对象写入 SQL TIMESTAMP 列时,它将日期调整到哪个时区,计算机的日期或日历对象(或其他)中指定的日期?

                  When Hibernate writes a Java Calendar object to an SQL TIMESTAMP column, to which time zone does it adjust the date, that of the computer or that specified in the calendar object (or some other)?

                  Hiberante 3.x 在 CalendarType 中使用以下内容(参见 HB-1006):

                  Hiberante 3.x uses the following in the CalendarType (see HB-1006):

                  public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
                      final Calendar cal = (Calendar) value;
                      //st.setTimestamp( index,  new Timestamp( cal.getTimeInMillis() ), cal ); //JDK 1.5 only
                      st.setTimestamp( index,  new Timestamp( cal.getTime().getTime() ), cal );
                  }
                  

                  所以 Hibernate 使用 PreparedStatement#setTimestamp(int, Timestamp, Calendar) 使用日历的时区.

                  So Hibernate uses PreparedStatement#setTimestamp(int, Timestamp, Calendar) which uses the time zone of the calendar.

                  当 Hibernate 将 TIMESTAMP 读入日历对象时,它将日期转换到哪个时区?

                  When Hibernate reads the TIMESTAMP into the calendar object, to which time zone does it translate the date?

                  好吧,我们再来看看 CalendarType 类:

                  Well, again, let's look at the CalendarType class:

                  public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
                  
                      Timestamp ts = rs.getTimestamp(name);
                      if (ts!=null) {
                          Calendar cal = new GregorianCalendar();
                          if ( Environment.jvmHasTimestampBug() ) {
                              cal.setTime( new Date( ts.getTime() + ts.getNanos() / 1000000 ) );
                          }
                          else {
                              cal.setTime(ts);
                          }
                          return cal;
                      }
                      else {
                          return null;
                      }
                  
                  }
                  

                  因此,Hibernate 使用默认时区和默认语言环境中的当前时间构造一个默认GregorianCalendar.

                  So Hibernate constructs a default GregorianCalendar using the current time in the default time zone with the default locale.

                  作为旁注,我强烈建议阅读以下问题:

                  As a side note, I highly suggest to read the following question:

                  • 夏令时和时区最佳做法

                  这篇关于Hibernate 在读取 Java 日历对象并将其写入 SQL TIMESTAMP 时使用哪个时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何将 Timestamp 转换为 Date 或 DateTime 对象? 下一篇:按 T​​imeStamp 升序排列 Firestore 数据

                  相关文章

                  最新文章

                  <i id='VrvJx'><tr id='VrvJx'><dt id='VrvJx'><q id='VrvJx'><span id='VrvJx'><b id='VrvJx'><form id='VrvJx'><ins id='VrvJx'></ins><ul id='VrvJx'></ul><sub id='VrvJx'></sub></form><legend id='VrvJx'></legend><bdo id='VrvJx'><pre id='VrvJx'><center id='VrvJx'></center></pre></bdo></b><th id='VrvJx'></th></span></q></dt></tr></i><div id='VrvJx'><tfoot id='VrvJx'></tfoot><dl id='VrvJx'><fieldset id='VrvJx'></fieldset></dl></div>

                  1. <small id='VrvJx'></small><noframes id='VrvJx'>

                    <tfoot id='VrvJx'></tfoot><legend id='VrvJx'><style id='VrvJx'><dir id='VrvJx'><q id='VrvJx'></q></dir></style></legend>
                    • <bdo id='VrvJx'></bdo><ul id='VrvJx'></ul>