I have string with value 2014-07-23 06:00
. I need to convert this value to DateTime in yyyy-MM-dd-HH.mm.ss.ffffff
format. Without converting to string in need to display in yyyy-MM-dd-HH.mm.ss.ffffff
But I am getting below error. Error - string was not recognized as a valid datetime
Below Is my Code. Can any one please help me to fix this one.
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
string format = "yyyy-MM-dd-HH.mm.ss.ffffff" ;
DateTime result;
const String Date = "2014-07-23 06:00"; ;
try
{
result = DateTime.ParseExact(Date, format,
CultureInfo.InvariantCulture);
Console.WriteLine("{0} converts to {1}.", format, result.ToString());
}
catch (FormatException)
{
Console.WriteLine("{0} is not in the correct format.", format);
}
}
}