I been trying to convert javascript date to c# datetime format to be inserted into microsoft sql database.
This is the codes i currently have:
Javascript side:
var now = new Date();
now = now.toUTCString();
C# side:
//time variable is in DateTime Format
Console.WriteLine("Before: "+time);
String timeString = Convert.ToString(time);
Console.WriteLine("Convert: "+timeString);
DateTime newDT = DateTime.ParseExact(timeString, "yyyy-MM-dd HH:mm:ss:FFF", CultureInfo.InvariantCulture);
Console.WriteLine("After: "+newDT);
Error Msg:
System.FormatException: String was not recognized as a valid DateTime.
at System.DateTimeParse.ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style)
at -classfile&method name omiited-(DateTime time)
Debug Info:
Before: 17/8/2015 11:43:48 AM
Convert: 17/8/2015 11:43:48 AM
I'm pretty sure that it is the "timeString" that is inside ParseExact is wrong.
Any ideas on how to solve this ? The format of the result i would want would be in this format: 2015-07-27 14:24:23.853 . Thanks!