I would like to be able to parse date and / or date-time values ββfrom a csv file and get their DateTime format (or in Excel NumberFormat expressions).
For example, I would like to pass the function "2008-06-07 00: 00: 00.000" and return something like "yyyy-MM-dd hh: mm: ss.000" to it.
The catch is that there can be many possible date formats in csv files, and they are not known in advance, so I cannot use DateTime.TryParseExact (), since you need to know the DateTime format string before the time to check if it works with a specific value.
Knowing the date format, I could set it as a custom number format in Excel and put it in a value, and it will display just like it was in the text of the csv file, and also be able to use it in Excel Formulas.
Of course, there can be ambiguity, so ideally it would be nice to get a list of possible date formats, and then check for several dates to remove some parameters by looking at the intersections of lists of possible date formats.
I just opened the NodaTime API, and it looks like it can do something like this, but I have not seen an example of code that will achieve this, since most questions regarding similar queries requested earlier versions, it did not seem to be supported .
Any other methods of this will also be taken into account.
Edit
, , , - .
, . , . ( , ) yyyy/dd/MM .
private static HashSet<string> _patterns;
public static HashSet<string> AllCulturedDateTimePatterns
{
get
{
if (_patterns != null)
return _patterns;
_patterns = new HashSet<string>();
var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
foreach (var culture in cultures)
{
_patterns.UnionWith(culture.DateTimeFormat.GetAllDateTimePatterns());
}
return _patterns;
}
}