【问题标题】:bind 2 column of table with 1cell in listbox将表格的 2 列与列表框中的 1 个单元格绑定
【发布时间】:2012-10-12 08:56:59
【问题描述】:

名称第一列:日期接收 名称第二列:日期发送

数据:

dateReceiving -------- dateSending

 2001/01/01     --------    2001/01/03
 2001/03/08     --------    2001/03/12
 2001/11/19     --------    2001/11/24
 2001/11/11     --------    2001/12/18

我想在列表框中显示发送和接收的时间差。

怎么做?

【问题讨论】:

    标签: wpf c#-4.0


    【解决方案1】:

    如果您在单元格中使用 DateTime,您可以执行以下操作:

    DateTime time1:您的第一列

    DateTime time2:你的第三栏

    时间跨度差异 = time2.Substract(time1);

    日期时间: http://msdn.microsoft.com/en-us/library/system.datetime.aspx

    时间跨度: http://msdn.microsoft.com/en-US/library/vstudio/system.timespan.aspx

    编辑: 如果您的问题是关于多重绑定 => Bind an element to two sources

    【讨论】:

      【解决方案2】:

      将每个日期值转换为 DateTime 对象,然后减去它们,这将创建一个适合您情况的时间跨度对象

      DateTime receivedDate = new DateTime(year, month, day);
      DateTime sendDate = new DateTime(year, month, day);
      
      TimeSpan ts = receivedDate - sendDate;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-03-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-03
        • 2012-03-20
        • 1970-01-01
        相关资源
        最近更新 更多