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

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

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

        <tfoot id='ULato'></tfoot>
        • <bdo id='ULato'></bdo><ul id='ULato'></ul>
      1. java到mysql.我需要从字符串参数转换为时间戳

        时间:2023-07-25

      2. <tfoot id='o5SyR'></tfoot>
        <legend id='o5SyR'><style id='o5SyR'><dir id='o5SyR'><q id='o5SyR'></q></dir></style></legend>
              <tbody id='o5SyR'></tbody>

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

                  <bdo id='o5SyR'></bdo><ul id='o5SyR'></ul>

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

                  本文介绍了java到mysql.我需要从字符串参数转换为时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试将字符串解析为时间戳,因为我需要将此数据保存在 bbdd mysql 上.

                  I'm trying to parser String to Timestamp because I need to save this data on bbdd mysql.

                  String dateString: "2018-10-17T22:37:10.000+0000";
                  java.sql.Timestamp timeStampDate = null;
                  try {
                          DateFormat formatter;
                          formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
                          Date date = (Date) formatter.parse(dateString);
                          timeStampDate = new Timestamp(date.getTime());
                  
                      } catch (ParseException e) {
                          log.debug("ERROR parser String to Timestamp to save bbdd. ", e.getMessage());
                      }
                  

                  当我运行我的应用程序时,我会收到以下捕获消息:

                  When I run my app I get this catch message:

                  ERROR 解析器字符串到时间戳以保存 bbdd.无法解析的日期:2018-10-17T22:37:10.000+0000"

                  ERROR parser String to Timestamp to save bbdd. Unparseable date: "2018-10-17T22:37:10.000+0000"

                  谁能帮帮我?

                  推荐答案

                  把你的掩码改成

                  DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSS");

                  所以你有

                  java.sql.Timestamp timeStampDate = null;
                  String dateString = "2018-10-17T22:37:10.000+0000";
                  
                  try {
                      DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
                      Date date = formatter.parse(dateString);
                      timeStampDate = new Timestamp(date.getTime());
                  
                  } catch (ParseException e) {
                      e.printStackTrace();
                  }
                  

                  顺便说一下你应该不需要cast Date

                  抱歉为我的懈怠,我匆忙中没有测试输出,根据@andreas 评论,正确的掩码实际上是 yyyy-MM-dd'T'HH:mm:ss.SSSZ

                  Apologies for my slackness, in my haste I did not test the output and as per @andreas comment, the correct mask is actually yyyy-MM-dd'T'HH:mm:ss.SSSZ

                  这篇关于java到mysql.我需要从字符串参数转换为时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Java 将 UTC 时间戳转换为本地 DateTime 下一篇:在 sql 查询中使用 java.sql.Timestamp 对象

                  相关文章

                  最新文章

                    <bdo id='BRSOr'></bdo><ul id='BRSOr'></ul>

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

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

                      <legend id='BRSOr'><style id='BRSOr'><dir id='BRSOr'><q id='BRSOr'></q></dir></style></legend>
                      <tfoot id='BRSOr'></tfoot>