【问题标题】:Check if time exists in date string typescriptCheck if time exists in date string typescript
【发布时间】:2022-12-27 18:04:03
【问题描述】:

I have this string returned to me 2022/2/23. And some other times 2022/2/23 16:32:23. I want to make this: if dateString has no time in it then blabla.

How can I check if my string has a time string in it?

【问题讨论】:

标签: typescript


【解决方案1】:

Try using includes to check if there is a : present:

const checkIfIncludesTime = (dateStr: string): boolean => dateStr.includes(':');

You can also use regex for this one:

const checkIfIncludesTime = (dateStr: string): boolean => /:/.test(dateStr);

Hope this helps

【讨论】:

    猜你喜欢
    • 2022-12-26
    • 2014-08-22
    • 1970-01-01
    • 2013-09-18
    • 1970-01-01
    • 2023-03-09
    • 2013-11-26
    • 2022-12-09
    • 2023-02-22
    相关资源
    最近更新 更多