Convert string to custom date format - c# razor -
i have mysql database storing events , events have dates. i'm pulling in event dates , they're outputting in html strings.
<ul id="latest-events"> @{ ientity[] latestevents = viewbag.latestevents; foreach (ientity event in latestevents) { <li class="item"> <span class="event-date"> @event["displaydate"] </span> <a href="#">@event["title"]</a> <span class="teaser">@html.raw(event["teaser"])</span> </li> } } </ul>
currently, format "10/31/2014 12:00:00 am"
i prefer oct 31
believe mmm d
format.
is possible?
var mydate = event["displaydate"]; var oldformat = "m/d/yyyy h:m:s"; var newformat = "mmm d"; var newdate = mydate.oldformat.convertto(newformat);
just clear, don't know c# why above convertto
not possible. possible convert string using datetime
?
you should able utilize razor phone call conversion:
@item.date.tostring("mmmm dd, yyyy")
another approach:
[displayformat(dataformatstring = "{mmmm 0:dd yyyy")] public datetime date { get; set; } @html.displayfor(d => d.date);
you do, datetime.parseexact
.
var date = datetime.parseexact(odate, format, cultureinfo.invariantculture);
another option, hope helps.
c# razor
No comments:
Post a Comment