什么是DateTime.FromOADate()在Java中的等价(双到日期时间在Java中) [英] What is the equivalent of DateTime.FromOADate() in Java (double to Datetime in Java)

查看:1204
本文介绍了什么是DateTime.FromOADate()在Java中的等价(双到日期时间在Java中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#的有一个 DateTime.FromOADate()方法。

什么是相当于 DateTime.FromOADate()中的的Java 的?

这是我的C#code:

This is my C# code :

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);

这是输出:

2014-05-14T17:00:21

2014-05-14T17:00:21

我如何转换这个字节数组到Java?

How can i convert this byte array to java?

推荐答案

你有没有意识到你的二进制数据是一个的 OLE自动化日期价值?

Did you realize that your binary data is the binary represantation of an OLE Automation date value?

因此​​,与其让,你应该得到一个从数组值。

So instead of getting long, you should get a double value from your array.

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

我觉得有效的问题应该是:?什么是DateTime.FromOADate()在Java中相当于

答案是:

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);
}

这篇关于什么是DateTime.FromOADate()在Java中的等价(双到日期时间在Java中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆