检测String内容是否为DateTime的方法 - RegExp? [英] Way to detect if String content is a DateTime - RegExp?
问题描述
可能重复:
一般解析字符串到日期
以下情况:
我需要检测String是否包含DateTime / Timestamp。问题是那些DateTimes有各种格式和粒度,例如:
I need to detect if a String contains a DateTime/Timestamp. The problem is that those DateTimes come in various formats and granularity such as:
2011-09-12
12-09-2011
12.09。 2011
2011-09-01-14:15
...还有更多变种
2011-09-12 12-09-2011 12.09.2011 2011-09-01-14:15 ... and many many more variations
我不需要理解语义(例如,在一天或几个月之间不同)我只需要检测80%最常见的DateTime变体。
I don't need to understand the semantics (e.g. distinct between day or months) I just need to detect let's say 80% of the most common DateTime variations.
我的第一个想法是使用RegExp - 我对此并不熟悉,而且我需要熟悉myselft以及DateTimes可以来的所有变体。
My first thought was using RegExp - which I'm far from being familiar with and also I would need to familiarize myselft with all variations in which DateTimes can come.
所以我的问题:
- 是否有人知道罐装RegExps来实现这个目标?
- 是否有一些Java库可以执行此任务?
谢谢!!
推荐答案
还有另一个相同上下文的问题,希望链接可以帮到你:日期时间格式的动态正则表达式
There is another question of same context, hope that link will help you: Dynamic regex for date time formats
这篇关于检测String内容是否为DateTime的方法 - RegExp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!