比较日期作为打字稿中的字符串 [英] Compare dates as strings in typescript
本文介绍了比较日期作为打字稿中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将两个日期作为打字稿中的字符串进行比较.我输入的内容如下:-
I am trying to compare two dates as strings in typescript. The input I have is as below :-
startWindow = '05/2014'
endWindow = '05/2018'
我需要编写一个函数来检查起始窗口是否大于结束窗口.
I need to write a function to check if the start Window is greater than the end Window.
两个输入均为字符串类型.
Both the inputs are of string type.
谢谢
推荐答案
您可以将其转换为日期,然后进行比较:
You can convert it to a date and then compare them:
function convertDate(d)
{
var parts = d.split('/');
return new Date(parts[1], parts[0]);
}
var start = convertDate('05/2014');
var end = convertDate('05/2018');
alert(start < end);
这篇关于比较日期作为打字稿中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文