How to check Regular Expression for Timestamp in GWT?

gwt, java, regex

Solution

Just something simple as only describing the pattern like this:

^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}(?: [AP]M)?(?: [+-]\d{4})?$

as any tentative of real date validation with a regex sounds inherently wrong.

I got the uppercase Z as RFC822 timezone, regex needs changes to comply to TZDs or general textual time zones.

Problem

What will be the regular expression for following Timestamp format ``` YYYY-MM-DD HH:mm:ss.S YYYY-MM-DD HH:mm:ss.S AM/PM YYYY-MM-DD HH:mm:ss.S AM/PM Z YYYY-MM-DD HH:mm:ss.S Z ``` Where ``` Y: year, M: Month, D: Date, H: hour, m: minute, s: second, S: Milisecond 3 digit only, Z: Time zone. ``` I am getting timestamp format in string format so want to validate it. How to check above regular expression in GWT?

Original source