给定一个 UTC 日期,您如何正确设置 Adaptive Card - Date Picker 的值?

Given a UTC date, how do you correctly set value for Adaptive Card - Date Picker?

这是卡片模板:

{
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "FactSet",
            "facts": [
                {
                    "title": "Given Date 1",
                    "value": "${string(dueDate)}"
                },
                {
                    "title": "Formatted Date 1",
                    "value": "{{DATE(${string(dueDate)}, COMPACT)}}"
                },
                {
                    "title": "Given Date 2",
                    "value": "${dueDateTicks}"
                },
                {
                    "title": "Formatted Date 2",
                    "value": "${formatTicks(int(dueDateTicks), 'yyyy-MM-dd')}"
                }
            ]
        },
        {
            "type": "Input.Date",
            "id": "date",
            "value": "${formatDateTime(dueDate, 'yyyy-MM-dd')}"
        }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.2"
}

这是给定数据的示例:

{
    "dueDate": "2020-11-30T21:00:00Z",
    "dueDateTicks": "637423668000000000"
}

当您在设计器预览中尝试此操作时,它会正确呈现(本地 @ GMT+8):2020-12-01

Given Date 1
2020-11-30T21:00:00Z
Formatted Date 1
12/1/2020

Given Date 2
637423668000000000
Formatted Date 2
2020-12-01

DatePicker Value
12/01/2020

see here

但在团队中,日期选择器和格式化日期值已关闭(本地 @ GMT+8):2020-11-30

Given Date 1
11/30/2020 21:00:00
Formatted Date 1
12/1/2020

Given Date 2
637423668000000000
Formatted Date 2
2020-11-30

DatePicker Value
30 Nov 2020

see here

Activity class 有一个“LocalTimestamp”字段,您应该使用该字段根据用户的区域设置实例化日期。参见 here for more info. Dealing with this is obviously platform specific (you haven't said what platform you're on), but for C#, for instance, you can deal with this via the DateTimeOffset