How to convert date to 'ccyymmddhhmmss' format?

How to convert date to "ccyymmddhhmmss" format in C #?

+3
source share
3 answers

You might want to try this ... I don't know if cc is enabled, so I decided for cc.

DateTime time = DateTime.Now;
string format = "yyMMddhhmmss";
Console.WriteLine(((Convert.ToInt32(time.ToString("yyyy")) / 100) + 1).ToString() + time.ToString(format));

For "yyMMddhhmmss" ..... Try this ... And do not forget that capital Mis the month and lowercase Mis the minutes.

DateTime dt = Convert.ToDateTime("8 Oct 10 19:00");
Console.WriteLine(dt.ToString("yyMMddhhmmss"));
+6
source

From what I understand from your question, do you want to format a C # date object in the specified format?

- date.ToString( "yyyyMMddHHmmss" ) - - Date... - , 12-, 24- .. - http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx , .

, .

+2

@ Chris_techno25: I decided to extend the answer:

If we stick to the issue of Narashima, he wants a format ccyymmddhhmmss. So I scratched this extension method:

public static string IncludeCentury(this DateTime sourceDate, bool replace)
{
  var source = String.Format("{0}/{1}", sourceDate.Year / 100 + 1, sourceDate);
  if(replace)
    return Regex.Replace(source, "[^0-9]", "");
  else
    return source;
}

Using:

var includingCentury = DateTime.Now.IncludeCentury(true)
var includingCentury = DateTime.Now.IncludeCentury(false)

Conclusion:

21218201491410
21/2/18/2014 9:18:10 AM
0
source

All Articles