如何在 Ballerina 中比较两次?
How to compare two times in Ballerina?
我想使用 Ballerina 比较两个时间字符串。下面是我的方法。
time:Time|error t1 = time:parse("2017-06-26T09:46:22.444-0500",
"yyyy-MM-dd'T'HH:mm:ss.SSSZ");
time:Time|error t2 = time:parse("2017-06-25T09:46:22.444-0500",
"yyyy-MM-dd'T'HH:mm:ss.SSSZ");
if (t1 is time:Time && t2 is time: Time){
if (t1 < t2){
io: println("t2 is greater");
}
}
但是我得到了错误operator '<' not defined for 'ballerina/time:Time'.
有什么方法可以在 Ballerina 中比较两次?
time:Time|error t1 = time:parse("2019-06-23T09:46:21.441-0500", "yyyy-MM-dd'T'HH:mm:ss.SSSZ");
time:Time|error t2 = time:parse("2018-06-25T09:46:22.445-0500", "yyyy-MM-dd'T'HH:mm:ss.SSSZ");
if (t1 is time:Time && t2 is time: Time) {
if (t1.time < t2.time) {
io:println("t2 is greater");
} else {
io:println("t1 is greater");
}
}
我想使用 Ballerina 比较两个时间字符串。下面是我的方法。
time:Time|error t1 = time:parse("2017-06-26T09:46:22.444-0500",
"yyyy-MM-dd'T'HH:mm:ss.SSSZ");
time:Time|error t2 = time:parse("2017-06-25T09:46:22.444-0500",
"yyyy-MM-dd'T'HH:mm:ss.SSSZ");
if (t1 is time:Time && t2 is time: Time){
if (t1 < t2){
io: println("t2 is greater");
}
}
但是我得到了错误operator '<' not defined for 'ballerina/time:Time'.
有什么方法可以在 Ballerina 中比较两次?
time:Time|error t1 = time:parse("2019-06-23T09:46:21.441-0500", "yyyy-MM-dd'T'HH:mm:ss.SSSZ");
time:Time|error t2 = time:parse("2018-06-25T09:46:22.445-0500", "yyyy-MM-dd'T'HH:mm:ss.SSSZ");
if (t1 is time:Time && t2 is time: Time) {
if (t1.time < t2.time) {
io:println("t2 is greater");
} else {
io:println("t1 is greater");
}
}