Reputation: 683
I want to convert a DateTime
instance (DataTime.Now
) in YYYY-MM-DD HH:MM:SS
.
The output should remain a DateTime
, not a string
. How to do this?
Upvotes: 1
Views: 178
Reputation: 98740
It is not possible.
DateTime
structure doesn't have any implicit format. It just have date and time values. You can only have a format with textual representation which is string
representation.
The concept of a format only applies when you're converting to a string
.
Upvotes: 2
Reputation: 156948
That is not possible. A DateTime
is a struct containing numerical values, it does not contain any formatting information. That information is stored in the CurrentCulture
, specifically the DateTimeFormat
.
The information in the CurrentCulture
is shared across the entire thread, so if you do change that format, it will change for your entire application. If you want to format just that instance, use ToString
with your appropriate format.
Upvotes: 1