c# – Java中DateTime.FromOADate()的等价物(Java中的日期时间为
发布时间:2020-12-15 23:43:32 所属栏目:百科 来源:网络整理
导读:C#有一个DateTime.FromOADate()方法. Java中的DateTime.FromOADate()相当于什么? 这是我的C#代码: var b = new byte[8];b[0] = 0x20;b[1] = 0x64;b[2] = 0xa8;b[3] = 0xac;b[4] = 0xb6;b[5] = 0x65;b[6] = 0xe4;b[7] = 0x40;var dbl = BitConverter.ToDoub
C#有一个DateTime.FromOADate()方法.
Java中的DateTime.FromOADate()相当于什么? 这是我的C#代码: var b = new byte[8]; b[0] = 0x20; b[1] = 0x64; b[2] = 0xa8; b[3] = 0xac; b[4] = 0xb6; b[5] = 0x65; b[6] = 0xe4; b[7] = 0x40; var dbl = BitConverter.ToDouble(b,0); var dt = DateTime.FromOADate(dbl); 这是输出:
如何将此字节数组转换为java? 解决方法
您是否意识到您的二进制数据是
OLE Automation date值的二进制represantation?
因此,您应该从数组中获取double值,而不是变长. var b = new byte[8]; b[0] = 0x20; b[1] = 0x64; b[2] = 0xa8; b[3] = 0xac; b[4] = 0xb6; b[5] = 0x65; b[6] = 0xe4; b[7] = 0x40; var dbl = BitConverter.ToDouble(b,0); var dt = DateTime.FromOADate(dbl); Console.WriteLine("{0:s}",dt); 结果是: 2014-05-14T17:00:21 我认为有效的问题应该是:Java中的DateTime.FromOADate()相当于什么? 答案是: public static Date fromDoubleToDateTime(double OADate) { long num = (long) ((OADate * 86400000.0) + ((OADate >= 0.0) ? 0.5 : -0.5)); if (num < 0L) { num -= (num % 0x5265c00L) * 2L; } num += 0x3680b5e1fc00L; num -= 62135596800000L; return new Date(num); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |