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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pravin MoreRank #1,419 · 1.2K reputationPosted Sep 21, 2011, 8:58 PM EDT
Thanx,
Pravin.
Hemant KumarRank #1,202 · 1.5K reputationPosted Sep 21, 2011, 10:36 PM EDT
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
Prabhu RajaRank #861 · 2.6K reputationPosted Sep 22, 2011, 1:34 AM EDT
Thank You
Anand Uchagawkar48 reputationPosted Sep 23, 2011, 5:33 AM EDT
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
Anand Uchagawkar48 reputationPosted Sep 23, 2011, 5:36 AM EDT
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);