在 Azure Logic App 中是否有可用于计算年龄的 JS 代码?
Is there a JS code that i can use to calculate age in Azure Logic App?
在 Azure Logic Apps 中是否有可用于根据生日计算年龄的 JS 代码?
这个我已经试过了(它对我不起作用):
function calculate_age(dob) {
var diff_ms = Date.now() - dob.getTime();
var age_dt = new Date(diff_ms);
return Math.abs(age_dt.getUTCFullYear() - 1970);
}
calculate_age(new Date(workflowContext.actions.Parse_JSON.outputs.body.profile.birthYear, workflowContext.actions.Parse_JSON.outputs.body.profile.birthMonth, workflowContext.actions.Parse_JSON.outputs.body.profile.birthDay));
输出:{"body":null}
这个问题,只需要在最后一行前加上return
即可。
function calculate_age(dob) {
var diff_ms = Date.now() - dob.getTime();
var age_dt = new Date(diff_ms);
return Math.abs(age_dt.getUTCFullYear() - 1970);
}
return calculate_age(new Date(workflowContext.actions.Parse_JSON.outputs.body.profile.birthYear, workflowContext.actions.Parse_JSON.outputs.body.profile.birthMonth - 1, workflowContext.actions.Parse_JSON.outputs.body.profile.birthDay));
注意月份是 0 索引的,正如 Maxim 提到的那样。
当你想得到结果时,你可以按照下面的截图来做:
整个表达式是:
string(outputs('Execute_JavaScript_Code')?['body'])
希望对你有帮助~
在 Azure Logic Apps 中是否有可用于根据生日计算年龄的 JS 代码?
这个我已经试过了(它对我不起作用):
function calculate_age(dob) {
var diff_ms = Date.now() - dob.getTime();
var age_dt = new Date(diff_ms);
return Math.abs(age_dt.getUTCFullYear() - 1970);
}
calculate_age(new Date(workflowContext.actions.Parse_JSON.outputs.body.profile.birthYear, workflowContext.actions.Parse_JSON.outputs.body.profile.birthMonth, workflowContext.actions.Parse_JSON.outputs.body.profile.birthDay));
输出:{"body":null}
这个问题,只需要在最后一行前加上return
即可。
function calculate_age(dob) {
var diff_ms = Date.now() - dob.getTime();
var age_dt = new Date(diff_ms);
return Math.abs(age_dt.getUTCFullYear() - 1970);
}
return calculate_age(new Date(workflowContext.actions.Parse_JSON.outputs.body.profile.birthYear, workflowContext.actions.Parse_JSON.outputs.body.profile.birthMonth - 1, workflowContext.actions.Parse_JSON.outputs.body.profile.birthDay));
注意月份是 0 索引的,正如 Maxim 提到的那样。
当你想得到结果时,你可以按照下面的截图来做:
string(outputs('Execute_JavaScript_Code')?['body'])
希望对你有帮助~