Use DateTime.ParseExact:
DateTime time = DateTime.ParseExact("20101127", "yyyyMMdd", null);
nullwill use the current culture, which is somewhat dangerous. You can also specify a specific culture, for example:
DateTime time = DateTime.ParseExact("20101127", "yyyyMMdd", CultureInfo.InvariantCulture);
source
share