Last active
April 19, 2016 07:35
-
-
Save birdinforest/63b3c781a5b8e8b303884b2bc3420bd6 to your computer and use it in GitHub Desktop.
+ Convert DateTime to a formatted string and get DateTime by a formatted string. +Strip non-ASCII characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Globalization; | |
using System.Text.RegularExpressions; | |
public class Test | |
{ | |
public static void Main() | |
{ | |
// NOTE: This string contains non-ASCII characters | |
string dateTimeString = "21-10-2014 15:40:30"; | |
// Strip non-ASCII characters | |
dateTimeString = Regex.Replace(dateTimeString, @"[^\u0000-\u007F]", string.Empty); | |
string inputFormat = "dd-MM-yyyy HH:mm:ss"; | |
string outputFormat = "yyyy-MM-dd HH:mm:ss"; | |
var dateTime = DateTime.ParseExact(dateTimeString, inputFormat, CultureInfo.InvariantCulture); | |
string output = dateTime.ToString(outputFormat); | |
Console.WriteLine(output); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment