如何将双倍转换为时间? [英] How do I convert a double to a time?

查看:118
本文介绍了如何将双倍转换为时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

42998.578472222223





应该在太平洋标准时间今天下午1点左右?



should be around 1PM PST today??

DateTime.FromOADate(42998.578472222223)



没有给出正确答案



我尝试过:



尝试了各种时间戳转换


doesn't give the right answer

What I have tried:

tried various time stamp conversions

推荐答案

这看起来像是编码值的本地化时间。如果在澳大利亚布里斯班转换:

This looks like a localized time to where the value was encoded. If converted here in Brisbane, Australia:
double dateValue = 42998.578472222223;
DateTime convertedDate = DateTime.FromOADate(dateValue); // 20/09/2017 1:53:00 PM
DateTime localDate = convertedDate.ToLocalTime();        // 20/09/2017 11:53:00 PM
DateTime utcDate = convertedDate.ToUniversalTime();      // 20/09/2017 3:53:00 AM


Quote:

42998.578472222223

42998.578472222223



这是一个'Excel DateTime编码'。

整数部分是自开始日起的天数,应该是01/01/1900左右。

小数部分是当天的时间。

1是24小时

0.75是18小时

0.50是12小时

0.25是6小时

等等。

0.578472222223是13:53或1:53 PM


This is an 'Excel DateTime encoding'.
The integer part is number of days since starting day which should be around 01/01/1900.
the decimal part is the time in the current day.
1 is 24 hours
0.75 is 18 hours
0.50 is 12 hours
0.25 is 6 hours
and so on.
0.578472222223 is 13:53 or 1:53 PM


在之前的答案之后,我只是尝试了以下内容SQL Server 2014



After the previous answers, I just tried the following in SQL Server 2014

DECLARE @d DECIMAL = 42998
DECLARE @t DECIMAL = 0.578472222223 * ( 60*60*24 )
SELECT DATEADD(ss,@t,DATEADD(dd,@d,'1900-01-01'))





它的收益率 2017-09-22 13:53:00.000 这不是今天的日期。



但这可能是有意义的:

https://support.microsoft.com/en-us/help/ 214326 / excel-incorrect-assume-that-the-year-1900-a-aap-year [ ^ ]



那么这个呢?



and it yields 2017-09-22 13:53:00.000 which is not today's date.

But this may be of interest:
https://support.microsoft.com/en-us/help/214326/excel-incorrectly-assumes-that-the-year-1900-is-a-leap-year[^]

So then this?

SELECT DATEADD ( ss , @t , DATEADD ( dd , @d - CASE WHEN @d < 60 THEN 1 ELSE 2 END , '1900-01-01' ) )


这篇关于如何将双倍转换为时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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