我让datetime导出是"CAST(0x0000987C00000000 AS DateTime)“,但是当我想将它返回到datetime.It时,它是一个空值。我怎样才能让它再次出现在datetime上。
发布于 2017-05-11 18:43:43
对于那些在C#中寻找解决方案的人。例如,当读取脚本数据库数据时。
string pattern = @"CAST\(0x(\w{8})(\w{8}) AS DateTime\)";
Regex r = new Regex(pattern);
Match m = r.Match(hex);
int d = System.Convert.ToInt32("0x" + m.Groups[1].Value, 16);
int t = System.Convert.ToInt32("0x" + m.Groups[2].Value, 16);
DateTime converted = new DateTime(1900, 1, 1).AddDays(d).AddSeconds(t/300);在这里,我使用了正则表达式,因为我的输入格式如下:"CAST(0x0000A53E00E1A17B AS DateTime)",但是您可以使用SubString()或其他方法来获取DateTime字符串。
https://stackoverflow.com/questions/4946292
复制相似问题