Processing of a string in the view - Asp.net MVC

Asked

Viewed 91 times

0

I have a public string TimeUpdate { get; set; } in my model that is of the form "13-12-2016 17:12:09".I need that in the view it appears only the hours and the minutes, as I can do the field treatment?

PS: I have tried [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:t}")] but without success. I thank you in advance.

  • @Gypsy omorrisonmendez will this is duplicate if the field is String and there the field is a DateTime, there are differences, there is no such conversion?

  • Good, [DisplayFormat] does not work in this case. It must have converted a DateTime standard for string if it is in Model. I might even vote to reopen.

  • My concern was whether or not to be duplicate, because, the data are different and to DateTime would be a duplicate, but String no, by conversion. @Ciganomorrisonmendez

  • 2

    All right. It’s reopened. I’m not answering. Just link the answer I gave to the other: http://answall.com/questions/162550/formata%C3%A7%C3%a3o-de-exibi%C3%A7%C3%a3o-de-data-displayfor? noredirect=1&lq=1

  • @Mario because you use it like this: public string TimeUpdate { get; set; } ??? you made some additional code?

  • I didn’t want to explain how I get this information so as not to prolong the question, but it’s the following: This is a model of a REST request and the returned Json is a field of type "timeUpdate": "14-12-2016 10:15:34". I already tried to change the type to Datetime only that I get 01/01/0001 00:00:00 then I don’t know how to treat it... =/

  • @Mario your problem then is before this question, which is to transform a JSON an object. If I were you would create a new question of how to receive a REST which has a date in this format "13-12-2016 17:12:09" with Json.NET and then use the solution made by the Gypsy in that link would be better, because, I could even propose a solution in this class but, could be considered a gambiarra

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.