How do I get a date time format in C# that will look like this:
2011-09-01 00:00:00:000
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Anand UchagawkarPosted Sep 23, 2011, 9:36 AM
The above mentioned solution is for the InvaraintCulture/En-Us cultur, if your application is running under some different culture then use below code.
DateTime dtNow = DateTime.Now;
string strDateTimeFormat = dtNow.ToString("yyyy-MM-dd HH:mm:ss:fff", CultureInfo.InvariantCulture);
Anand UchagawkarPosted Sep 23, 2011, 9:33 AM
For the format which you require use below code,
DateTime dtNow = DateTime.Now;
string strDateTimeFormat = dtNow.ToString("yyyy-MM-dd HH:mm:ss:fff");
In case you need to know about the formats visit the following link http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
Prabhu RajaPosted Sep 22, 2011, 5:34 AM
Thank You
Hemant KumarPosted Sep 22, 2011, 2:36 AM
You need help with DateTime format strings in the C# language or other .NET languages. The framework provides powerful formatting capabilities, but the syntax is confusing and there are some tricks. Here we see examples of using DateTime formats, and also the different values you can get with the individual formats.
Please refer this link
http://www.dotnetperls.com/datetime-format
Pravin MorePosted Sep 22, 2011, 12:58 AM
Thanx,
Pravin.