Apache flex java中的Flex数据格式验证

Apache flex java中的Flex数据格式验证,apache-flex,date-formatting,Apache Flex,Date Formatting,我有一个XLSX文件,其中包含两列,一列是格式化的日期、时间或日期时间字段,另一列是FLEX类型的相关格式字符串。因此,该文件包含具有格式化值的Flex日期格式字符串。此文件可以包含一千多条此类组合记录。 例如: 年月日L:NN:SS A------1958年7月4日上午11:34:30 年月日------2009年7月13日 L:NN:SSA------下午1:24:20 我需要知道的是,我是否可以验证这个给定的日期,右侧的时间或日期时间值是根据左侧给定的FLEX格式格式化的。 重要的是,这需

我有一个XLSX文件,其中包含两列,一列是格式化的日期、时间或日期时间字段,另一列是FLEX类型的相关格式字符串。因此,该文件包含具有格式化值的Flex日期格式字符串。此文件可以包含一千多条此类组合记录。 例如:

年月日L:NN:SS A------1958年7月4日上午11:34:30

年月日------2009年7月13日

L:NN:SSA------下午1:24:20

我需要知道的是,我是否可以验证这个给定的日期,右侧的时间或日期时间值是根据左侧给定的FLEX格式格式化的。
重要的是,这需要在java端实现。

只需创建一个格式化程序并将字符串解析为日期

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

String s = "7/4/1958 11:34:30 AM";
SimpleDateFormat formatter=new SimpleDateFormat();
try {
    Date d = formatter.parse(s);
} catch (ParseException e) {
    e.printStackTrace();
    //This means the format was wrong 
} 

Thx,我需要知道的是给定的字符串是否按照文件中给定的格式格式化,我对此表示怀疑。您需要flex或flex格式代码来检查是否存在这种情况请参见此处格式字符串的模式和逻辑:您必须解析flex格式字符串,然后检查值。不过,只需检查格式化值是否有效,就需要对其进行解析了。非常感谢。这似乎满足了我的要求。
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

Boolean function checkValidity(String date, String flexFormat)
    String s = date;
    String str = flexFormat;
    SimpleDateFormat formatter=new SimpleDateFormat();
    try {

        String f = buildFormatString(str);
        formatter.applyPattern(f);

        Date d = formatter.parse(s);
        System.out.println(d);
        String nd = formatter.format(d);
        if(nd.compareTo(s) == 0) {
            return true;
        } else {
            return false;
        }
    } catch (ParseException e) {
        e.printStackTrace();
        //This means the format was wrong 
    }
    return false;
}

//This function changes the Flex date format to the java date format
//It will not work if the Flex format has text other than the recognised formatting characters.
private static String buildFormatString(String str) {
//      The mask pattern. 
//      You compose a pattern String using specific uppercase letters, for example: YYYY/MM.
//
//      The DateFormatter pattern String can contain other text in addition to pattern letters. To form a valid pattern String, you only need one pattern letter.
//
//      The following table describes the valid pattern letters:
//
//      Pattern letter Description 
//      Y Year. If the number of pattern letters is two, the year is truncated to two digits; otherwise, it appears as four digits. The year can be zero-padded, as the third example shows in the following set of examples: 
//      YY = 05 
//      YYYY = 2005 
//      YYYYY = 02005 

        String jFormat = str;
        jFormat = jFormat.replaceAll("Y", "y");

//       
//      M Month in year. The format depends on the following criteria: 
//      If the number of pattern letters is one, the format is interpreted as numeric in one or two digits. 
//      If the number of pattern letters is two, the format is interpreted as numeric in two digits. 
//      If the number of pattern letters is three, the format is interpreted as short text. 
//      If the number of pattern letters is four, the format is interpreted as full text. 
//      Examples: 
//      M = 7 
//      MM= 07 
//      MMM=Jul 
//      MMMM= July 


//       
//      D Day in month. While a single-letter pattern string for day is valid, you typically use a two-letter pattern string. 
//      Examples:
//
//      D=4 
//      DD=04 
//      DD=10 

        jFormat = jFormat.replaceAll("D", "d");

//       
//      E Day in week. The format depends on the following criteria: 
//      If the number of pattern letters is one, the format is interpreted as numeric in one or two digits. 
//      If the number of pattern letters is two, the format is interpreted as numeric in two digits. 
//      If the number of pattern letters is three, the format is interpreted as short text. 
//      If the number of pattern letters is four, the format is interpreted as full text. 
//      Examples: 
//      E = 1 
//      EE = 01 
//      EEE = Mon 
//      EEEE = Monday 



//       
//      A am/pm indicator. 

        jFormat = jFormat.replaceAll("A", "a");

//      H Hour in day (1-24). 
        jFormat = jFormat.replaceAll("H", "k");


//      J Hour in day (0-23). 
        jFormat = jFormat.replaceAll("J", "H");


//      K Hour in am/pm (0-11). 
        //jFormat = jFormat.replaceAll("K", "K");

//      L Hour in am/pm (1-12).
        jFormat = jFormat.replaceAll("L", "h");

//      N Minute in hour.
        jFormat = jFormat.replaceAll("N", "m");

//      Examples:
//
//      N = 3 
//      NN = 03 
//       
//      S Second in minute. 
        jFormat = jFormat.replaceAll("S", "s");

//      Example:
//
//      SS = 30 
//       
//      Q Millisecond in second
        jFormat = jFormat.replaceAll("Q", "S");

//      Example:
//
//      QQ = 78 
//      QQQ = 078 
//       
//      Other text You can add other text into the pattern string to further format the string. You can use punctuation, numbers, and all lowercase letters. You should avoid uppercase letters because they may be interpreted as pattern letters. 
//      Example:
//
//      EEEE, MMM. D, YYYY at L:NN:QQQ A = Tuesday, Sept. 8, 2005 at 1:26:012 PM 
//       
//
//      Language Version:
//      3.0
//      Player Version:
//      Flash 9, AIR 1.1
//      Product Version:
//      Flex 3
        return jFormat;
    }