In my system the date format is set as YYY-MM-DD
format.So my c# application will take this format when i call DateTime.Now
which is fine.
Now in installed my application as service using Install util command.
After running services it gets the开发者_StackOverflow社区 date format as dd/mm/yyy
.
But i want to save the format as yyy-MM-DD
format in database.
Whether i need to change my code or i can set this format in system.
because already the regional settings are done in yyy-mm-dd
format only.
This problem happens only when I install my application as a service.
Please help. Thanks in advance.
First a question to you: why do you store the date as a string in your database? I would strongly suggest to store it as a date value instead. This would eliminate any formatting problems when storing data.
As a second suggestion, I would make sure to format the string explicitly, rather than relying on system settings, if you need to store it in a specific format:
var dateAsString = theDate.ToString("yyyy-MM-dd");
Use the DateTime formatting:
DateTime.Now.ToString("yyy-MM-dd");
That will get you:
yyy
: The year (same asyyyy
), e.g.2011
MM
: The month number (single digit is formatted with leading zero)
dd
: The day number (single digit is formatted with leading zero)
In my system the date format is set as YYY-MM-DD format
In Regional Settings?
That only sets the format for the current user. Hence has no effect on processes running as another user as service processes nearly always do.
精彩评论