0

In an XML that I am parsing, I have the following:

<event>
    <book>Felicity Fly</book>
    <author>Christina Gabbitas</author>
    <bookImgUrl>http://www.whsmith.co.uk/Images/Products\957\255\9780957255203_t_f.jpg</bookImgUrl>
    <info>Christina Gabbitas will be signing copies of her new book, Felicity Fly. Books should be bought from WHSmith. Proof of purchase may be necessary</info>
    <date>20 Apr 2013</date>
    <startTime>10:30</startTime>
    <location>
        <name>WHSmith Chester</name>
        <address>5-7 Foregate Street</address>
        <city>Chester</city>
        <county>Cheshire</county>
        <postcode>CH1 1HH</postcode>
        <tel>01244 321106</tel>
    </location>
</event>

I want to create a DateTime object from the two nodes <date> and <startTime>. So I am doing this:

var EventEntity = new Event()
{
    Book = e.Book,
    BookImgUrl = e.BookImgUrl,
    Info = e.Info,
    Start = new DateTime().**?**
};

But When I press the dot [.] after the DateTime object, I am not getting the Parse method from Intellisense, why is this? What am I doing wrong?

I was planning on using the solution outlined in this post.

1 Answer 1

1

Parse is a static method but you are calling it as it were an instance method. You should call it in this way:

var EventEntity = new Event()
{
    Book = e.Book,
    BookImgUrl = e.BookImgUrl,
    Info = e.Info,
    Start = DateTime.ParseExact(...) // or DateTime.TryParseExact(...)
};
Sign up to request clarification or add additional context in comments.

3 Comments

Thank You Daniele. And will this format be correct "dd MMM YYYY HH:mm" if I add my date and startTime with a space in between them?
I meant if I concatenate my date and startTime with a blank space between them.
I haven't tried the format, but it sounds good to me. You have to pay attention to the culture, otherwise your month will not be parsed correctly (InvariantCulture is not mean to work for everything; there are some posts about it ...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.