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

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

    <tfoot id='dXhjV'></tfoot>

        <bdo id='dXhjV'></bdo><ul id='dXhjV'></ul>
      1. java DateTimeFormatterBuilder 在测试时间失败

        java DateTimeFormatterBuilder fails on testtime(java DateTimeFormatterBuilder 在测试时间失败)

        1. <legend id='96ZqE'><style id='96ZqE'><dir id='96ZqE'><q id='96ZqE'></q></dir></style></legend>
          <i id='96ZqE'><tr id='96ZqE'><dt id='96ZqE'><q id='96ZqE'><span id='96ZqE'><b id='96ZqE'><form id='96ZqE'><ins id='96ZqE'></ins><ul id='96ZqE'></ul><sub id='96ZqE'></sub></form><legend id='96ZqE'></legend><bdo id='96ZqE'><pre id='96ZqE'><center id='96ZqE'></center></pre></bdo></b><th id='96ZqE'></th></span></q></dt></tr></i><div id='96ZqE'><tfoot id='96ZqE'></tfoot><dl id='96ZqE'><fieldset id='96ZqE'></fieldset></dl></div>
            <bdo id='96ZqE'></bdo><ul id='96ZqE'></ul>
            • <small id='96ZqE'></small><noframes id='96ZqE'>

                <tbody id='96ZqE'></tbody>

                  <tfoot id='96ZqE'></tfoot>
                  本文介绍了java DateTimeFormatterBuilder 在测试时间失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我对 DateTimeFormatterBuilder 有一个简单的 jUnit 测试.在运行时,当 Spring-MVC 处理程序 (@RequestParam)

                  I have a simple jUnit test for DateTimeFormatterBuilder. At runtime it works, when some String comes on Spring-MVC hanlder (@RequestParam)

                  在测试时它以相同的 String 值失败.

                  At testtime it fails with the same String value.

                  测试值:25-May-2018 11:10

                  待测方法:

                  public void getTimeDifference(@RequestParam String startDate, @RequestParam String endDate) {
                      DateTimeFormatter DATE_TIME_FORMAT = new DateTimeFormatterBuilder().parseCaseInsensitive().appendPattern("dd-MMM-yyyy HH:mm").toFormatter();
                      LocalDateTime.parse(startDate,DATE_TIME_FORMAT);
                      return   messages;
                  }
                  

                  测试方法:

                  @Test
                  public void testFormat() throws Exception {
                      final String startDateFormatA = "25-May-2018 11:10";
                      final String endDateFormatA = "25-May-2018 11:10";
                      assertEquals("06:00", callDbController.getTimeDifference(startDateFormatA, endDateFormatA)[1]);
                  }
                  

                  我的测试:在运行时我设置一个断点并在 Display-View 上测试它:

                  My Test: At runtime I set a break-point and test it on Display-View:

                  LocalDateTime.parse("25-May-2018 11:10",DATE_TIME_FORMAT)
                  

                  在测试时使用相同的 spring-aplication-context 我在运行时做同样的事情,但它失败了.

                  At testtime with the same spring-aplication-context I do the same like on runtime and it fails.

                  有人有想法吗?

                  推荐答案

                  月份名称是英文的,所以你最好在formatter中设置一个java.util.Locale.

                  The month name is in English, so you'd better set a java.util.Locale in the formatter.

                  如果不设置,格式化程序将使用 JVM 默认语言环境.而且如果不是英文,可能会报错(而且不同的环境可能有不同的配置,所以最好设置locale而不是依赖JVM的默认值).

                  If you don't set it, the formatter will use the JVM default locale. And if it's not English, you might get an error (and different environments might have different configurations, so it's better to set the locale instead of relying on the JVM's default).

                  只需执行 toFormatter(Locale.ENGLISH) 而不是 toFormatter() 即可.

                  Just do toFormatter(Locale.ENGLISH) instead of just toFormatter() and that's it.

                  这篇关于java DateTimeFormatterBuilder 在测试时间失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
                  Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
                  How to convert Integer to int?(如何将整数转换为整数?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
                  Inconsistent behavior on java#39;s ==(java的行为不一致==)
                  Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)

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

                    <small id='8PEmm'></small><noframes id='8PEmm'>

                      <bdo id='8PEmm'></bdo><ul id='8PEmm'></ul>

                          1. <tfoot id='8PEmm'></tfoot>

                            <legend id='8PEmm'><style id='8PEmm'><dir id='8PEmm'><q id='8PEmm'></q></dir></style></legend>