日期:2014-05-19  浏览次数:20721 次

How can i convert a 8 bytes array into datetime?
How   can   i   convert   a   8   bytes   array   into   datetime?

The   8   bytes   array   was   read   from   a   binary   file   written   by   delphi   .

i   read   the   array   into   an   array   and   try   to   convert   it   to   datetime.

But   i   was   fail.

i   had   try   this


    long   testLong   =   BitConverter.ToInt64(hexString,0);                        
    DateTime   dt   =   new   DateTime(testLong);
 

and   this


            double   doub   =   BitConverter.ToDouble(hexString,   0);
              long   testLong   =   BitConverter.DoubleToInt64Bits(doub);
            DateTime   dt   =   new   DateTime(testLong);

they   both   faild   to   give   me   the   right   things....

What   should   i   do???

 

 

 


------解决方案--------------------
string s1 = Encoding.Default.GetString(b);
DateTime t ;
DateTime.TryParse(s1,out t);

------解决方案--------------------
贼烂的英语。。。中国人就用中文了贝

还i was fail ... ...

如果Delphi写入到文件中的是datetime的字符表达,就用c#转回来,用DateTime.Parse()解析。
如果是DateTime的long形式。就new DateTime(long)
------解决方案--------------------
object tmpObj;
BinaryFormatter formatter = new BinaryFormatter();
Stream stream = File.OpenRead(path);
tmpObj = formatter.Deserialize(stream);
stream.Close();
convert.toDateTime(tmpObj);
上面是我从文本留里读数据不知道可不可以