Reputation: 6496
I am trying to extract datetime info from
"2012/04/03 10:06:21:611747"
using format
String dateformat = @"yyyy/mm/dd hh:mm:ss:ffffff";
Getting an exception - any help is appreciated.
Full code
String dateformat = @"yyyy/mm/dd hh:mm:ss:ffffff";
readonly CultureInfo _provider = CultureInfo.InvariantCulture;
DateTime dateTime = DateTime.ParseExact(line, dateformat, _provider);
Upvotes: 1
Views: 1625
Reputation: 2676
Use
String dateformat = @"yyyy/MM/dd hh:mm:ss:ffffff";
Use MM for month.
The exception was ocurring due to confusion in interpreting m at two different places.
Upvotes: 1
Reputation: 12776
Use MM
for months:
String dateformat = @"yyyy/MM/dd hh:mm:ss:ffffff";
Upvotes: 7
Reputation: 11418
Your format should be:
yyyy/MM/dd hh:mm:ss:ffffff
You have a lower case m
for month which is incorrect.
Have a look at this answer for more info: .Net: DateTime String format
Upvotes: 5
Reputation: 57573
You should use
String dateformat = @"yyyy/MM/dd hh:mm:ss:ffffff";
MM
is for month, while mm
is for minutes!!
Upvotes: 3