I have a string in this format: “20111027”, i.e. of the general format: “yyyyMMdd”.
How do I convert this to a DateTime having the timezone GMT?
This code does some conversion, but it’s unclear what timezone would be used:
DateTime date = DateTime.ParseExact(dateString, "yyyyMMdd",
CultureInfo.InvariantCulture);
Use a
DateTimeStylesofAssumeUniversal:From the docs of
DateTimeStyles.AssumeUniversal:Sounds like exactly what you want 🙂
(Alternatively you could use Noda Time and parse it to a
LocalDate. It only represents a date, after all, so why use a type which cares about times and time zones? 🙂