Вопрос

I have string which in the following format :130606082236. Now this needs to be converted into DateTime format as 2013-06-06 08:22:36,000. How do I create a custom format method and convert this ?

Это было полезно?

Решение

Use DateTime.ParseExact:

DateTime.ParseExact("130606082236", "yyMMddhhmmss", CultureInfo.InvariantCulture);

Другие советы

Try:

    DateTime time = DateTime.ParseExact("130606082236", "yyMMddHHmmss", null);//new DateTime(2013, 06, 06, 08, 22, 36);
    Console.WriteLine(time.ToLongTimeString());
    Console.WriteLine(time.ToString("yyMMddHHmmss"));

Otherwords the Method: DateTime.ParseExact with Format yyMMddHHmmss

Format Specification available here

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top