开发者

How do I read IE Cookie timestamps as DateTime?

I was trying to read IE cookie file开发者_运维百科 using C#

I am stuck with how to read the datetime inside the file.

They divide the datetime into 2 lines like this

481435648

30298937

or

1100239232

30151908

I have tried all methods to convert this to readable date time but I failed. I have read about FileTime, nanoseconds and ticks, and none of those got me on the right path.


According to this post there is only one field for expiration date (the second one could be the cookie value ? )and to read it, you can use something like

DateTime expires = new DateTime(1970, 1,1).AddSeconds(secondsFromCookie);
Console.WriteLine(expires);

The above is applicable only for netscape cookie file format. For IE use

        int eLow = 481435648;
        int eHigh = 30298937;
        double seconds = 1e-7*(eHigh*Math.Pow(2, 32) + eLow) - 11644473600;
        DateTime expires = new DateTime(1970, 1, 1).AddSeconds(seconds);

Source of the formula


I ended up with this:

long leastSignificant = 481435648;
long mostSignificant = 30298937;
var fileTime = (mostSignificant << 32) + leastSignificant;

DateTime cookieTime = DateTime.FromFileTimeUtc(fileTime);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜