- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
需要了解为什么我会得到时差。
这是我的 VBA 代码:
Public OHLCArray(1 To 481, 0 To 28, 0 To 3) As Single
'debug stmt below
Dim DebugTime As Double
OHLCArray(1, 0, 3) = Now()
'next 3 lines are debugging lines
DebugTime = OHLCArray(1, 0, 3)
Print #1, "Now()=" & DebugTime
Print #1, Now & "Debug print line - (just before pushing"
Now()=42527.4609375
06/06/2016 11:01:00 AMDebug print line - (just before pushing
06/06/2016 10:59:34 AM - Skipped ws_calculate routine - CurrentTimeID already processed - CurrentTimeID = 45
06/06/2016 10:59:54 AM - Skipped ws_calculate routine - CurrentTimeID already processed - CurrentTimeID = 45
最佳答案
任何使用 Single
的实例在日期的上下文中给你的正确答案是一个极端的巧合。
为了进一步说明为什么,基于 Gary 的回答,我反转了您的代码,使数组声明为 Double
- 当我们想要比较实际正确的 Double
时,这会更容易。与 Single
相比-cast-to- Double
这将是不正确的。
Sub testTime()
Dim OHLCArray(1 To 481, 0 To 28, 0 To 3) As Double
'debug stmt below
Dim DblTime As Double, SngTime As Single
OHLCArray(1, 0, 3) = Now()
'next 3 lines are debugging lines
DblTime = OHLCArray(1, 0, 3)
SngTime = OHLCArray(1, 0, 3)
Debug.Print "Doubletime: " & DblTime
Debug.Print "Singletime: " & SngTime
Debug.Print " Date Double Single Double(single2)"
Debug.Print "Singletime = " & CDate(SngTime) & " - " & CDbl(SngTime) & " - " & CSng(SngTime) & " - " & CDbl(SngTime2)
Debug.Print "Doubletime = " & CDate(DblTime) & " - " & CDbl(DblTime) & " - " & CSng(DblTime)
Debug.Print "Now() = " & Now() & " - " & CDbl(Now()) & " - " & CSng(Now())
Debug.Print "Now = " & Now & " - " & CDbl(Now) & " - " & CSng(Now)
End Sub
Double
进行比较在下一行:
Doubletime: 42528,3991666667
Singletime: 42528,4
Date Double Single
Singletime = 07.06.2016 09:33:45 - 42528,3984375 - 42528,4
Doubletime = 07.06.2016 09:34:48 - 42528,3991666667 - 42528,4
Now() = 07.06.2016 09:34:48 - 42528,3991666667 - 42528,4
Now = 07.06.2016 09:34:48 - 42528,3991666667 - 42528,4
Doubletime: 42528,3995138889
Singletime: 42528,4
Date Double Single
Singletime = 07.06.2016 09:33:45 - 42528,3984375 - 42528,4
Doubletime = 07.06.2016 09:35:18 - 42528,3995138889 - 42528,4
Now() = 07.06.2016 09:35:18 - 42528,3995138889 - 42528,4
Now = 07.06.2016 09:35:18 - 42528,3995138889 - 42528,4
Doubletime: 42528,3996180556
Singletime: 42528,4
Date Double Single
Singletime = 07.06.2016 09:33:45 - 42528,3984375 - 42528,4
Doubletime = 07.06.2016 09:35:27 - 42528,3996180556 - 42528,4
Now() = 07.06.2016 09:35:27 - 42528,3996180556 - 42528,4
Now = 07.06.2016 09:35:27 - 42528,3996180556 - 42528,4
Doubletime: 42528,3998726852
Singletime: 42528,4
Date Double Single
Singletime = 07.06.2016 09:33:45 - 42528,3984375 - 42528,4
Doubletime = 07.06.2016 09:35:49 - 42528,3998726852 - 42528,4
Now() = 07.06.2016 09:35:49 - 42528,3998726852 - 42528,4
Now = 07.06.2016 09:35:49 - 42528,3998726852 - 42528,4
Doubletime: 42528,4045486111
Singletime: 42528,41
Date Double Single
Singletime = 07.06.2016 09:45:00 - 42528,40625 - 42528,41
Doubletime = 07.06.2016 09:42:33 - 42528,4045486111 - 42528,41
Now() = 07.06.2016 09:42:33 - 42528,4045486111 - 42528,41
Now = 07.06.2016 09:42:33 - 42528,4045486111 - 42528,41
Single
的日期转换,时间戳实际上在很长一段时间内都是静态的,因为数据类型不能支持足够的数字。
Double
的事实产生更多的数字并不一定是正确的——它变得稍微准确一些,但仍然不正确。
Now
或
Now()
!如我的示例所示,只要使用正确的数据类型,它们都会产生正确的结果。
Single
引起的。而不是
Double
.
Now
或者更有可能,
Print
在运行时做一些时髦的事情。尝试在
Print
前加上前缀
Debug.Print "Now: " & Now
的声明然后根据
documentation 将结果与日志文件进行比较,或者更好。 ,改变这个:
Print #1, Now & "Debug print line - (just before pushing"
Print #1, CDate(Now) & "Debug print line - (just before pushing"
Date data is written to the file using the standard short date format recognized by your system. When either the date or the time component is missing or zero, only the part provided gets written to the file.
Single
时出现的神秘额外数字至
Double
,这不是编译器完成的近似值,正如我之前错误猜测的那样。这是数字表示方式的已知副作用,显然是
common topic在计算机科学中。
Type conversion. The Double structure provides an explicit interface implementation for the IConvertible interface, which supports conversion between any two standard .NET Framework data types. Language compilers also support the implicit conversion of values of all other standard numeric types to Double values. Conversion of a value of any standard numeric type to a Double is a widening conversion and does not require the user of a casting operator or conversion method.
However, conversion of Int64 and Single values can involve a loss of precision.
The problem of precision most frequently affects Single values that are converted to Double values.
For example, 2/10, which is represented precisely by .2 as a decimal fraction, is represented by .0011111001001100 as a binary fraction, with the pattern "1100" repeating to infinity. In this case, the floating-point value provides an imprecise representation of the number that it represents. Performing additional mathematical operations on the original floating-point value often increases its lack of precision. For example, if you compare the results of multiplying .3 by 10 and adding .3 to .3 nine times, you will see that addition produces the less precise result, because it involves eight more operations than multiplication. Note that this disparity is apparent only if you display the two Single values by using the "R" standard numeric format string, which, if necessary, displays all 9 digits of precision supported by the Single type.
关于vba - 使用 VBA Now 与 Now() 时的时间差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37667404/
我对 EPOCH 时间有疑问。 我需要计算两个数据包之间的时间差。我不太确定如何: printf("Epoch Time: %d:%d seconds\n", header->ts.tv_sec, h
我正在尝试了解数字旋转的速度。我有一个程序,其中计数器从 0 开始。 每次用户单击按钮“加 1”。它将计数器递增 1。 计数器最大值为 255。在 255 之后它回到 0。 现在我想显示从 0 到递增
基本上我想做的是根据 SIP 信令获取通话持续时间。 我有一个包含如下所示记录的表,我正在尝试编写一个返回以下内容的 SELECT 语句: id callid date
您好,我需要有关 MySQL 数据库查询的帮助。 我有一个看起来像这样的表: ID TRACKID DATE Name Action 38
细节。我有包含以下列的注释表。 ID - INT(3) Date - DateTime Note - VARCHAR(100) Tile - Varchar(100
午夜过后我很难计算时间: String time = "15:00-18:05"; //Calculating OK //String time = "22:00-01:05"; //Not
我使用 XML 从 MySQL 数据库中抓取了两个日期,如下所示。我想获得以秒为单位的时差。 我写了这个脚本,但它给出了“NaN” function show(){ var t1 = new Dat
如何在 MYSQL phpMyAdmin 数据库中以 (TIME 00:00:00) 格式更新另一个字段(整列)的时间差 当我在 PHP 中执行此操作时,我不断收到 0:00:00 并且没有结果。其
我的表单中有两个字段,用户可以在其中选择输入时间(开始时间、结束时间),我想在更改这些字段时重新计算另一个字段的值。 我想做的是获取 2 次之间的小时数。因此,例如,如果我的开始时间为 5:30,结束
我想使用 Date 和 Calendar 类计算 java 中两个日期/时间之间的差异。我的格式是“2012-01-24 12:30:00 PM”。 我已经实现了我自己的方法,也用谷歌搜索它以与其他人
MySQL 服务器上的访客数据库如下所示id 是主键整数类型,firstname 和 lastname 是文本类型,访客 id 是整数类型 id firstname lastname
我是一名优秀的程序员,十分优秀!