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

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

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

      1. 如何在java中获取给定的日期字符串格式(模式)?

        How to get the given date string format(pattern) in java?(如何在java中获取给定的日期字符串格式(模式)?)
        <i id='UkeGl'><tr id='UkeGl'><dt id='UkeGl'><q id='UkeGl'><span id='UkeGl'><b id='UkeGl'><form id='UkeGl'><ins id='UkeGl'></ins><ul id='UkeGl'></ul><sub id='UkeGl'></sub></form><legend id='UkeGl'></legend><bdo id='UkeGl'><pre id='UkeGl'><center id='UkeGl'></center></pre></bdo></b><th id='UkeGl'></th></span></q></dt></tr></i><div id='UkeGl'><tfoot id='UkeGl'></tfoot><dl id='UkeGl'><fieldset id='UkeGl'></fieldset></dl></div>
          <bdo id='UkeGl'></bdo><ul id='UkeGl'></ul>
          <tfoot id='UkeGl'></tfoot>
          <legend id='UkeGl'><style id='UkeGl'><dir id='UkeGl'><q id='UkeGl'></q></dir></style></legend>
            <tbody id='UkeGl'></tbody>

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

                1. 本文介绍了如何在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中获取给定的日期字符串格式(模式)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                    <i id='kIySu'><tr id='kIySu'><dt id='kIySu'><q id='kIySu'><span id='kIySu'><b id='kIySu'><form id='kIySu'><ins id='kIySu'></ins><ul id='kIySu'></ul><sub id='kIySu'></sub></form><legend id='kIySu'></legend><bdo id='kIySu'><pre id='kIySu'><center id='kIySu'></center></pre></bdo></b><th id='kIySu'></th></span></q></dt></tr></i><div id='kIySu'><tfoot id='kIySu'></tfoot><dl id='kIySu'><fieldset id='kIySu'></fieldset></dl></div>

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

                          • <bdo id='kIySu'></bdo><ul id='kIySu'></ul>
                              <tbody id='kIySu'></tbody>
                          • <legend id='kIySu'><style id='kIySu'><dir id='kIySu'><q id='kIySu'></q></dir></style></legend>

                            <tfoot id='kIySu'></tfoot>