Hi All I am using DateTime class to do some processing on dates. The issue I am facing is that in some cases i would like it to initialize to date component excluding the year part of date. How do i do that? E开发者_StackOverflow社区xample: For date 11/March/2011, I only want to store 11-March. How do i do that? Thanks
You can't with the DateTime class (actually a struct). You can ignore the year value in your processing, however. You could also create your own class to do what you want.
You can't to that with DateTime because it is used to represent a specific moment time. Since a day and a month are not sufficient information to represent a date, you can't store these information in DateTime only.
Maybe you should explain further what you would like to achieve.
If your concern is about outputting/formatting this date please view the following document in MSDN for format options you can apply to the toString() method of DateTime.
MSDN: Standard Date and Time Format Strings
Something you could do if you are really forced to use DateTime is to rebase each entered date to a specific year, although I can't see how this should make any sense, especially when it comes to leap years
One way you can do this is to use the TimeSpan
structure. Then you can use that on top of any DateTime
calculations you need
精彩评论