public static DateTime Decode(string date)
{
if (date.StartsWith("D:"))
date = date.Substring(2);
int year, month = 1, day = 1, hour = 0, minute = 0, second = 0;
int offsetHour = 0, offsetMinute = 0;
char variation = '\0';
year = int.Parse(date.Substring(0, 4));
if (date.Length >= 6) {
month = int.Parse(date.Substring(4, 2));
if (date.Length >= 8) {
day = int.Parse(date.Substring(6, 2));
if (date.Length >= 10) {
hour = int.Parse(date.Substring(8, 2));
if (date.Length >= 12) {
minute = int.Parse(date.Substring(10, 2));
if (date.Length >= 14) {
second = int.Parse(date.Substring(12, 2));
}
}
}
}
}
DateTime d = new DateTime(year, month, day, hour, minute, second);
if (date.Length <= 14)
return d;
variation = date[14];
if (variation == 'Z')
return d.ToLocalTime();
if (date.Length >= 17) {
offsetHour = int.Parse(date.Substring(15, 2));
if (date.Length >= 20) {
offsetMinute = int.Parse(date.Substring(18, 2));
}
}
TimeSpan span = new TimeSpan(offsetHour, offsetMinute, 0);
if (variation == '-')
d += span;
else
d -= span;
return d.ToLocalTime();
}