31 декабря 2016 в 15:10
декабря is not English.
декабря = December
DateTime.Parse("31/December/2016").ToString("yyyymmdd"); => 20161231
DateTime.Parse("31/декабря/2016").ToString("yyyymmdd"); => Error
31 декабря 2016 в 15:10 => 20161231
How do I convert it?
The DateTime
format above should be converted using TryParseExact
with GetCultureInfo
set to Russian culture like this:
String example = "31/декабря/2016"; // December 31, 2016
DateTime result;
bool check;
check = DateTime.TryParseExact(example, "dd/MMMM/yyyy", CultureInfo.GetCultureInfo("ru-RU"), DateTimeStyles.None, out result);
String converted = result.ToString("yyyyMMdd");
Console.WriteLine(check);
Console.WriteLine(converted);
The output returned by console is:
True
20161231
NB: To convert date with spaces instead of slashes between date components, change "dd/MMMM/yyyy"
to "dd MMMM yyyy"
(use another format to convert time part together).
Working example: .NET Fiddle Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With