public static XVar db2time(XVar _param_str) { #region pass-by-value parameters XVar str = _param_str.Clone(); #endregion int day, hour, minute, month, second, year; bool havedate = false, havetime = false, isdst = DateTime.Now.IsDaylightSavingTime(); if (str.Type == typeof(DateTime)) { year = ((DateTime)str.Value).Year; month = ((DateTime)str.Value).Month; day = ((DateTime)str.Value).Day; hour = ((DateTime)str.Value).Hour; minute = ((DateTime)str.Value).Minute; second = ((DateTime)str.Value).Second; havedate = true; havetime = hour > 0 || minute > 0 || second > 0; } else { if (str.IsNumeric()) { XVar len; string pattern; havedate = true; len = str.Length(); if (10 <= len) { havetime = true; } switch (len.ToInt()) { case 14: pattern = "(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})"; break; case 12: pattern = "(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})"; break; case 10: pattern = "(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})"; break; case 18: pattern = "(\\d{4})(\\d{2})(\\d{2})"; break; case 6: pattern = "(\\d{2})(\\d{2})(\\d{2})"; break; case 4: pattern = "(\\d{2})(\\d{2})"; break; case 2: pattern = "(\\d{2})"; break; default: return(new XVar()); } Match parsed = Regex.Match(str, pattern); if (parsed.Groups[1].Value != "") { year = int.Parse(parsed.Groups[1].Value); month = parsed.Groups.Count > 2 ? int.Parse(parsed.Groups[2].Value) : 1; day = parsed.Groups.Count > 3 ? int.Parse(parsed.Groups[3].Value) : 1; hour = parsed.Groups.Count > 4 ? int.Parse(parsed.Groups[4].Value) : 0; minute = parsed.Groups.Count > 5 ? int.Parse(parsed.Groups[5].Value) : 0; second = parsed.Groups.Count > 6 ? int.Parse(parsed.Groups[6].Value) : 0; } else { return(new XVar()); } } else { if (str.IsString()) { if (Regex.IsMatch(str, "(\\d{4})-(\\d{1,2})-(\\d{1,2}) (\\d{1,2}):(\\d{1,2}):(\\d{1,2})")) { Match parsed = Regex.Match(str, "(\\d{4})-(\\d{1,2})-(\\d{1,2}) (\\d{1,2}):(\\d{1,2}):(\\d{1,2})"); year = int.Parse(parsed.Groups[1].Value); month = int.Parse(parsed.Groups[2].Value); day = int.Parse(parsed.Groups[3].Value); hour = int.Parse(parsed.Groups[4].Value); minute = int.Parse(parsed.Groups[5].Value); second = int.Parse(parsed.Groups[6].Value); havedate = true; havetime = true; } else { if (Regex.IsMatch(str, "(\\d{4})-(\\d{1,2})-(\\d{1,2})")) { Match parsed = Regex.Match(str, "(\\d{4})-(\\d{1,2})-(\\d{1,2})"); year = int.Parse(parsed.Groups[1].Value); month = int.Parse(parsed.Groups[2].Value); day = int.Parse(parsed.Groups[3].Value); hour = 0; minute = 0; second = 0; havedate = true; } else { if (Regex.IsMatch(str, "(\\d{2})-(\\d{1,2})-(\\d{1,2})")) { Match parsed = Regex.Match(str, "(\\d{2})-(\\d{1,2})-(\\d{1,2})"); year = DateTime.Now.Year; month = DateTime.Now.Month; day = DateTime.Now.Day; hour = int.Parse(parsed.Groups[1].Value); minute = int.Parse(parsed.Groups[2].Value); second = int.Parse(parsed.Groups[3].Value); havetime = true; } else { return(new XVar()); } } } } else { return(new XVar()); } } } if (!havetime) { hour = 0; minute = 0; second = 0; } if (!havedate) { year = DateTime.Now.Year; month = DateTime.Now.Month; day = DateTime.Now.Day; } return(new XVar(0, year, 1, month, 2, day, 3, hour, 4, minute, 5, second)); }