Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert date time with milliseconds to double or int?

Tags:

c#

datetime

I have a string looking good in the following way:

TimeString = "2011.01.02 22:06:52.091"

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.

Edit:

The time is kind of time stamp for financial currency quote:

Time bid ask

2011.01.02 22:06:52.091 1.5000 1.5001

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?

like image 319
Wenhao.SHE Avatar asked Jan 31 '26 22:01

Wenhao.SHE


1 Answers

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;

turns it into a double

like image 118
Keith Nicholas Avatar answered Feb 02 '26 10:02

Keith Nicholas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!