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

查看:9
本文介绍了如何在 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?

推荐答案

只是一些简单的事情,只描述这样的模式:

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.

我将大写 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天全站免登陆