如何在GWT中检查时间戳的正则表达式? [英] How to check Regular Expression for Timestamp in GWT?

查看:136
本文介绍了如何在GWT中检查时间戳的正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是以下时间戳格式的正则表达式

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

其中

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.

如何在GWT中检查上面的正则表达式?

How to check above regular expression in GWT?

推荐答案

像这样:

^\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.

我将大写字母Z作为RFC822时区,正则表达式需要根据TZD或一般文本时区进行更改。

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

这篇关于如何在GWT中检查时间戳的正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆