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

      <legend id='G4oVt'><style id='G4oVt'><dir id='G4oVt'><q id='G4oVt'></q></dir></style></legend>

        • <bdo id='G4oVt'></bdo><ul id='G4oVt'></ul>
      1. <small id='G4oVt'></small><noframes id='G4oVt'>

        如何将 java.sql.Timestamp(yyyy-MM-dd HH:mm:ss.S) 格式化为

        时间:2023-07-26
            <tbody id='o81zc'></tbody>
          <i id='o81zc'><tr id='o81zc'><dt id='o81zc'><q id='o81zc'><span id='o81zc'><b id='o81zc'><form id='o81zc'><ins id='o81zc'></ins><ul id='o81zc'></ul><sub id='o81zc'></sub></form><legend id='o81zc'></legend><bdo id='o81zc'><pre id='o81zc'><center id='o81zc'></center></pre></bdo></b><th id='o81zc'></th></span></q></dt></tr></i><div id='o81zc'><tfoot id='o81zc'></tfoot><dl id='o81zc'><fieldset id='o81zc'></fieldset></dl></div>

              <tfoot id='o81zc'></tfoot>

              <legend id='o81zc'><style id='o81zc'><dir id='o81zc'><q id='o81zc'></q></dir></style></legend>

                <small id='o81zc'></small><noframes id='o81zc'>

                  <bdo id='o81zc'></bdo><ul id='o81zc'></ul>
                  本文介绍了如何将 java.sql.Timestamp(yyyy-MM-dd HH:mm:ss.S) 格式化为日期(yyyy-MM-dd HH:mm:ss)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  嗯,我有一个使用 Date 的详细信息,因为我从我的数据库和变量fecha"(日期)中获取了一个我正在获取的同一对象的对象java.sql.Timestamp,所以格式是毫秒,但我不希望毫秒出现.所以我需要将我从数据库接收到的日期格式化为没有毫秒的新日期.

                  Well, I'm having a detail using a Date, because I'm getting an Object from my DataBase and in the variable "fecha" (date) from that same object I'm getting a java.sql.Timestamp, so the formatt is with miliseconds, but i don't want the miliseconds to appear. So i need to formatt the date that I'm receiving from my DB to a new date that doesn't have miliseconds.

                  这是 Factura 的对象:

                  This is the object Factura:

                  public class Factura  implements java.io.Serializable {
                  
                   private FacturaId id;
                   ...
                   private boolean activo;
                   private Date fecha;
                  }
                  

                  在映射到数据库的 xml 中,我有这个变量fecha"的代码:

                  In the xml that is mapped to the DB I have this code for that variable "fecha":

                  <property name="fecha" type="timestamp">
                    <column length="19" name="fecha" not-null="true"/>
                  </property>
                  

                  在数据库中该列是 fecha DATETIME.

                  当我从我的数据库中获得一个对象 Factura 时,我得到了这种日期 2013-10-10 10:49:29.0 但我希望它没有.0(毫秒).

                  And when I get an object Factura from my DB I'm getting this kind of date 2013-10-10 10:49:29.0 but I want it without the .0 (miliseconds).

                  我试过这个(facturaFactura 对象):

                  I've tried this (factura is the Factura object):

                  try {
                     SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                     Date fechaNueva = null;
                     String fechaStr = factura.getFecha().toString();
                     int tamaño = fechaStr.length()-2;
                     fechaStr = fechaStr.substring(0, tamaño); //I get a string without the miliseconds
                     fechaNueva = format.parse(fechaStr);
                  } catch(ParseException ex) {
                     ...
                  }
                  

                  但是 fechaNueva 给了我 Thu Oct 10 10:49:29 CDT 2013 而我只想要 2013-10-10 10:49:29,你能帮帮我吗?

                  But fechaNueva is giving me Thu Oct 10 10:49:29 CDT 2013 and I only want 2013-10-10 10:49:29, can you help me, please?

                  非常感谢,提前.

                  推荐答案

                  您根本不需要使用子字符串,因为您的 format 不包含该信息.

                  You do not need to use substring at all since your format doesn't hold that info.

                  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                  String fechaStr = "2013-10-10 10:49:29.10000";  
                  Date fechaNueva = format.parse(fechaStr);
                  
                  System.out.println(format.format(fechaNueva)); // Prints 2013-10-10 10:49:29
                  

                  这篇关于如何将 java.sql.Timestamp(yyyy-MM-dd HH:mm:ss.S) 格式化为日期(yyyy-MM-dd HH:mm:ss)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何为秒值打印高达 6 位精度的时间 下一篇:Java MySQL Timestamp 时区问题

                  相关文章

                  最新文章

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

                      <tfoot id='vD98s'></tfoot>
                    1. <legend id='vD98s'><style id='vD98s'><dir id='vD98s'><q id='vD98s'></q></dir></style></legend>

                      <small id='vD98s'></small><noframes id='vD98s'>