将毫秒的日期时间转换为double或int? [英] Convert date time with milliseconds to double or int?
问题描述
我有一个字符串看起来很好:
I have a string looking good in the following way:
TimeString = "2011.01.02 22:06:52.091"
现在我想将其转换为双倍,并将其保存为双数。我在c#中做,我该怎么做?
Now I wanna convert it to double, and save it as a double number. I am doing it in c#, how could I do it?
真的无法在线找到答案。
Really can not find answer online.
编辑:
时间是金钱货币报价的时间戳:
The time is kind of time stamp for financial currency quote:
时间出价要求
2011.01.02 22:06:52.091 1.5000 1.5001
2011.01.02 22:06:52.091 1.5000 1.5001
它是外汇报价时间的时间戳。我更喜欢这样:xxxxxxxxxxxxxx.ooo,xxxxxxxxxxxxxxx是从2011.01.02 22:06:52显示多少秒的int部分,而.ooo是毫秒,091你觉得如何?
it is the time stamp of Forex quote time. I prefer in this way: xxxxxxxxxxxxxxxx.ooo, the xxxxxxxxxxxxxxx is the int part to show how many seconds we have from "2011.01.02 22:06:52" and the .ooo is the milliseconds as "091" how do you think?
推荐答案
var span = DateTime.ParseExact(TimeString,
"yyyy.MM.dd HH:mm:ss.fff",
CultureInfo.InvariantCulture) -
new DateTime(2011, 01, 02, 22, 06, 52, 0);
double d = span.TotalMilliseconds/1000.0;
将其变成双重
这篇关于将毫秒的日期时间转换为double或int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!