I have an interface that is feeding me a datetimeupdated variable with the type of DateTime but I need to read it as type TimeSpan. I'm trying to do the conversion and it kind of worked but not really. I followed this post. Convert DateTime to TimeSpan
Code:
if (e.CmsData != null)
{
List<NewAgent> newAgentList = new List<NewAgent>();
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
{
foreach (var item in e.CmsData.Agents)
{
NewAgent newAgents = new ScoreBoardClientTest.NewAgent();
newAgents.AgentName = item.AgName;
newAgents.AgentExtension = item.Extension;
newAgents.AgentDateTimeChange = ConvertedDateTimeUpdated;
newAgents.AuxReasons = item.AuxReasonDescription;
newAgents.LoginIdentifier = item.LoginId;
ConvertedDateTimeUpdated = item.DateTimeUpdated - new DateTime(01/01/2000);
time = ConvertedDateTimeUpdated;
agentTime = time - DateTime.Now.TimeOfDay;
newAgents.AgentDateTimeStateChange = agentTime;
newAgentList.Add(newAgents);
}
datagrid.ItemsSource = newAgentList;
}));
}
XAML:
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding AgentName}" />
<DataGridTextColumn Header="Aux Reason" Binding="{Binding AuxReasons}" />
<DataGridTextColumn Header="Time" Binding="{Binding AgentDateTimeStateChange}" />
</DataGrid.Columns>
AgentClass
class NewAgent
{
public string AgentName { get; set; }
public int AgentExtension { get; set; }
public TimeSpan AgentDateTimeChange { get; set; }
public TimeSpan AgentDateTimeStateChange { get; set; }
public String AuxReasons { get; set; }
public string LoginIdentifier { get; set; }
}
When I print this out to my list I get the below pasted into the fields instead of a format of 00:00:00.
please let me know if this is not enough code to understand what I am trying to accomplish and I'll post all of what I have. Also important to note that item.datetimeupdated is in the format of 00/00/0000 00:00:00.