我有以下可能的字符串模式(空格是可变的):
2-4 Jun
8-11 Jun
8 Jun-11 Jun
20-Jun
28 Jun-01 Jul
15-18 Jun
我想要转换为Java日期,一个或两个。
有没有正则表达式的捷径?Iam正在迁移旧的excel电子表格(如果这有影响,则不会设置列的格式)
发布于 2012-02-15 00:24:13
如果我没理解错你的问题,这里有一个片段,它应该可以做到这一点,或者至少给你一些基础知识:
Matcher m = Pattern.compile("(\\d+)-(\\d+)?\\s*(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)").matcher(input);
while (m.find()) {
if (m.groupCount()==3) {
int first = Integer.valueOf(m.group(1));
int second = Integer.valueOf(m.group(2));
String month = m.group(3);
// DO something here
} else {
int first = Integer.valueOf(m.group(1));
String month = m.group(2);
// Do something here
}
}
https://stackoverflow.com/questions/9280142
复制相似问题