Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何计算gridview中注册的DateTime和DateTime.now之间的差异?_Asp.net_Datetime_Gridview - Fatal编程技术网

Asp.net 如何计算gridview中注册的DateTime和DateTime.now之间的差异?

Asp.net 如何计算gridview中注册的DateTime和DateTime.now之间的差异?,asp.net,datetime,gridview,Asp.net,Datetime,Gridview,我想计算注册日期时间(在数据库中)和DateTime之间的差异。现在gridview中的,但得到一个错误。我如何计算这些时间之间的差异?当我使用(Eval(“RegDtTime”)-DateTime.Now时,会出现以下错误:运算符“-”没有为类型“Object”和“Date”定义。我应该如何计算差异 <asp:GridView ID="GridView1" runat="server" AllowSorting="True"

我想计算注册日期时间(在数据库中)和
DateTime之间的差异。现在
gridview
中的
,但得到一个错误。我如何计算这些时间之间的差异?当我使用
(Eval(“RegDtTime”)-DateTime.Now
时,会出现以下错误:
运算符“-”没有为类型“Object”和“Date”定义。
我应该如何计算差异

     <asp:GridView
        ID="GridView1"

        runat="server" 
        AllowSorting="True" 
        AutoGenerateColumns="False" 
        DataKeyNames="ID" 
        DataSourceID="SqlDataSource1">
        <Columns>
            <asp:BoundField DataField="ID" 
                HeaderText="ID" 
                ReadOnly="True" 
                SortExpression="ID" />
            <asp:BoundField DataField="RegDtTime" 
                HeaderText="RegDtTime" 
                SortExpression="RegDtTime" />
            <asp:TemplateField>
                <ItemTemplate>
                    <div>
                            <asp:LinkButton ID="LinkButton1" 
                            runat="server" 
                            onclick="LinkButton1_Click" 
                            Text='<%# Bind("ID") %>'></asp:LinkButton>
                    </div>
                    <div>
                        RegDateTime:
                        <asp:Label ID="Label3" 
                            runat="server"                                                             
                            Text='<%# Bind("RegDtTime") %>'></asp:Label>
                    </div>
                    <div>
                        DateTimeNow:
                        <asp:Label ID="Label4" 
                            runat="server"                                 
                            Text='<%# DateTime.Now %>'></asp:Label>
                    </div>
                    <div>
                        Passed:
                        <asp:Label ID="Label5" 
                            runat="server"                                                                                             
                            Text='<%# (Eval("RegDtTime")-DateTime.Now %>'></asp:Label>
                    </div>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

注册日期时间:
DateTimeNow:
通过:

update error message.operator'-'没有为类型“Object”和“Date”定义。是的,这就解释了您的正确性?
Eval
正在返回一个
Object
。因此您需要
cast
将其转换为
DateTime
。那么如何计算它们呢?对减法的结果使用
TotalMinutes
属性。如下所示:
(Convert.ToDateTime(Eval(“LastDateTime”)-(DateTime.Now)).TotalMinutes