'Creating a C# List with a local DateTime value from an XML file
I'm trying to create a list based on this XML data: http://nfs.faireconomy.media/ff_calendar_thisweek.xml
I so far have:
private List<News> newsList;
newsList = new List<News>();
public class News
{
public string title { get; set; }
public string country { get; set; }
public DateTime date { get; set; }
public DateTime time { get; set; }
public DateTime localDateTime { get; set; }
public string impact { get; set; }
}
public void getNews()
{
String URLString = "http://nfs.faireconomy.media/ff_calendar_thisweek.xml";
var doc = XDocument.Load(URLString);
newsList = doc.Root
.Descendants("event")
.Select(node => new News
{
title = node.Element("title").Value,
country = node.Element("country").Value,
date = DateTime.ParseExact(node.Element("date").Value, "MM-dd-yyyy", CultureInfo.InvariantCulture),
time = DateTime.Parse(node.Element("time").Value, CultureInfo.InvariantCulture),
impact = node.Element("impact").Value
})
.ToList();
for (int i = 0; i < newsList.Count; i++)
{
Print(i + " | Title: " + newsList[i].title);
Print(i + " | Country: " + newsList[i].country);
Print(i + " | Date: " + newsList[i].date.Date);
Print(i + " | Time: " + newsList[i].time.TimeOfDay);
Print(i + " | Impact: " + newsList[i].impact);
}
}
I'm getting data into the list fine, and it is outputting fine.
What I'm struggling to achieve is how to convert the date and time fields from the XML into a 'localDateTime' in my list.
The XML date & time is in UTC and I want my list to store a single value that combines both the UTC date & time fields into a single local DateTime field.
Thanks in advance for any help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
