writing code - Global date format setting?

Topics: ASP.NET 2.0, Business Logic Layer, Controls
Oct 28, 2011 at 4:25 PM

Hi Ben, Rtur & All,

I see that lots of the date formating is specified in code. For example in the default theme the postview.aspx page formats the date created this way Post.DateCreated.ToString("d. MMMM yyyy HH:mm")

I personaly like dates in a different format and often use "MMMM dd yyyy HH:mm" or just "MMMM dd yyyy" (not uncommon here in the US)

I'm working on a new Related Posts Widget and need to optionally output a date into the html.  Is there a global date format anywhere in the system I can use rather than hardcoding the formatting? 

If not, does anyone mind if I add a web.config setting to hold the format for now?  I know it'd be better as a editable setting in the admin area but I don't have time to code that.  And configurable via web.config is better than hardcoded. 



Oct 28, 2011 at 10:06 PM

You could let user choose format instead of hardcoding it, right in that widget settings. Global format may not be all that useful, for example theme author might want to present date in particular way, post can have one format but comment another etc.

Nov 2, 2011 at 1:07 PM

Thanks rtur.  You make a good point especially regarding a widget.  I think I will just make it a widget setting. 

I think it would be useful though if there were 4 global date settings:

DateShort, DateLong, DateTimeShort and DateTimeLong.  Then the theme or widget creator could choose the one that makes the most sense for the given use and the blog ownen would have control of whether the month comes first or second and whether the time is in AM PM or 24 hour time.  Ideally these would be settings in the admin area.