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

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

      1. <i id='nIISG'><tr id='nIISG'><dt id='nIISG'><q id='nIISG'><span id='nIISG'><b id='nIISG'><form id='nIISG'><ins id='nIISG'></ins><ul id='nIISG'></ul><sub id='nIISG'></sub></form><legend id='nIISG'></legend><bdo id='nIISG'><pre id='nIISG'><center id='nIISG'></center></pre></bdo></b><th id='nIISG'></th></span></q></dt></tr></i><div id='nIISG'><tfoot id='nIISG'></tfoot><dl id='nIISG'><fieldset id='nIISG'></fieldset></dl></div>
          <bdo id='nIISG'></bdo><ul id='nIISG'></ul>
      2. 如何在java中获取给定的日期字符串格式(模式)?

        时间:2023-09-30

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

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

                • <tfoot id='Xxm85'></tfoot>

                    <tbody id='Xxm85'></tbody>
                  本文介绍了如何在java中获取给定的日期字符串格式(模式)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想获取给定日期字符串的格式.

                  I want to get the format of a given date string.

                  示例:我有一个类似 2011-09-27T07:04:21.97-05:00 的字符串,该字符串的日期格式是 yyyy-MM-dd'T'HH:mm:ss.SSS.

                  Example: I have a string like 2011-09-27T07:04:21.97-05:00 and the date format of this string is yyyy-MM-dd'T'HH:mm:ss.SSS.

                  在这里,我想在将字符串(2011-09-27T07:04:21.97-05:00)传递给将返回格式(yyyy-MM-dd'T'HH:mm:ss.SSS),然后我将根据我的要求格式化给定的日期字符串(like yy-mm--dd or mm/dd/yyyy).

                  Here I want to find out this date format when I pass string(2011-09-27T07:04:21.97-05:00) to a method which will return the format(yyyy-MM-dd'T'HH:mm:ss.SSS), then later I will format my given date string according to my requirement(like yy-mm--dd or mm/dd/yyyy).

                  谁能告诉我如何才能实现它?

                  Can any one tell me how can I get it achieved?

                  推荐答案

                  import java.text.ParseException;
                  import java.text.SimpleDateFormat;
                  import java.util.Date;
                  import java.util.regex.Matcher;
                  import java.util.regex.Pattern;
                  
                  public class NewClass {
                  
                      private static final String[] formats = { 
                                  "yyyy-MM-dd'T'HH:mm:ss'Z'",   "yyyy-MM-dd'T'HH:mm:ssZ",
                                  "yyyy-MM-dd'T'HH:mm:ss",      "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
                                  "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd HH:mm:ss", 
                                  "MM/dd/yyyy HH:mm:ss",        "MM/dd/yyyy'T'HH:mm:ss.SSS'Z'", 
                                  "MM/dd/yyyy'T'HH:mm:ss.SSSZ", "MM/dd/yyyy'T'HH:mm:ss.SSS", 
                                  "MM/dd/yyyy'T'HH:mm:ssZ",     "MM/dd/yyyy'T'HH:mm:ss", 
                                  "yyyy:MM:dd HH:mm:ss",        "yyyyMMdd", };
                  
                          /*
                           * @param args
                           */
                      public static void main(String[] args) {
                          String yyyyMMdd = "20110917";   
                          parse(yyyyMMdd);
                      }
                  
                      public static void parse(String d) {
                          if (d != null) {
                              for (String parse : formats) {
                                  SimpleDateFormat sdf = new SimpleDateFormat(parse);
                                  try {
                                      sdf.parse(d);
                                      System.out.println("Printing the value of " + parse);
                                  } catch (ParseException e) {
                  
                                  }
                              }
                          }
                      }
                  }
                  

                  这篇关于如何在java中获取给定的日期字符串格式(模式)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:SwingWorker 没有响应 下一篇:如何使用 String.format 使字符串居中?

                  相关文章

                  最新文章

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

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