我有一个字符串
1368352924.281610000
呈现日期时间
。
我该如何解析这个?
已尝试:
string rststr = Convert.ToString(result);
string[] rststrarr = rststr.Split('.');
DateTime.Parse(rststrarr[0]);
编辑 抱歉造成困惑。它指出这是一个高分辨率的unix时间戳。 亲切的问候。
最佳答案
这个数字很可能代表自 UTC 1970 年 1 月 1 日以来经过的秒数。这是“Unix Epoch”值,在许多系统和日期格式中都很常见。
假设我对您所拥有的值类型的判断是正确的,那么您可以执行以下操作:
// you said you were starting with a string
string s = "1368352924.281610000";
// but you are going to need it as a double.
// (If it's already a double, skip these two steps)
var d = double.Parse(s);
// starting at the unix epoch
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
// simply add the number of seconds that you have
DateTime dt = epoch.AddSeconds(d);
Debug.WriteLine("{0} {1}", dt, dt.Kind); // prints 05/12/2013 10:02:04 Utc
关于c# - 如何解析日期时间秒.ms,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16521591/