检查字符串是否为日期值 [英] Check if a string is a date value

查看:175
本文介绍了检查字符串是否为日期值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查某个值是否为有效日期,允许使用任何已知日期格式的简便方法是什么。

What is an easy way to check if a value is a valid date, any known date format allowed.

例如我的值 10-11-2009 10/11 / 2009 2009-11-10T07:00:00 + 0000 应该全部被识别为日期值,值 200 10 350 ,不应将其识别为日期值。如果可能的话,最简单的检查方法是什么?因为时间戳也是允许的。

For example I have the values 10-11-2009, 10/11/2009, 2009-11-10T07:00:00+0000 which should all be recognized as date values, and the values 200, 10, 350, which should not be recognized as a date value. What is the simplest way to check this, if this is even possible? Because timestamps would also be allowed.

推荐答案

Date.parse() 足够吗?

Would Date.parse() suffice?

查看其相对 MDN文档页面

这篇关于检查字符串是否为日期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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