最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to check if date string contains hoursminseconds part? - Stack Overflow

programmeradmin3浏览0评论

I have JS string with date: 21-05-2022. It is also possible to receive date string as 21-05-2022T23:15:56Z - date string with date and time data. I would like to check if ining string contains only date or date and time. Now I am using a function which splits string by 'T' symbol and checks if resulted array has second [1] member. Maybe there is more elegant way to perform this operation? I can use moment.js library in this context.

I have JS string with date: 21-05-2022. It is also possible to receive date string as 21-05-2022T23:15:56Z - date string with date and time data. I would like to check if ining string contains only date or date and time. Now I am using a function which splits string by 'T' symbol and checks if resulted array has second [1] member. Maybe there is more elegant way to perform this operation? I can use moment.js library in this context.

Share Improve this question edited May 8, 2022 at 17:32 TwittorDrive asked May 8, 2022 at 17:07 TwittorDriveTwittorDrive 1751 gold badge2 silver badges12 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Alt variant: let isTimeHas = /:/.test(dateString)

since your date is always string, i would do :
let result = dateString.includes('T'); if the string includes the T it means it is datetime

发布评论

评论列表(0)

  1. 暂无评论