How is “variant time” (DATE, double, 8-byte) handl

2019-07-15 11:23发布

问题:

I can't seem to find any information on how a "variant time" (DATE, double, 8-byte variable) is handled.... I have a variant time "A" which value is "41716.892329". If I convert "A" using "VariantTimeToSystemTime" (or "COleDateTime") - I get "2014-03-18 21:24:57".

  • How is this variant time calculated?
  • Is it capable of storing milliseconds?
  • Is there any way to determine if variant time is an AM or PM time?

I'm a bit confused regarding the AM/PM thing because the device that I'm working with at that moment was set to "09:24:57" (AM) and not "21:24:57" (PM).

Can this be a problem of the device SDK that provides me with an incorrect variant time?

EDIT: This was a problem of incorrect timezone set in the device (was set to "GMT-12:00" instead of "GMT-00:00")

Thanks.

回答1:

Ok, I think I've found all of my answers! As Simon Mourier commented, "41716.892329" is really "2014-03-18 21:24:57" and this is why - it looks like variant time is split like this: "(date) 41716 . (time) 892329". If you take "0.892329" and multiply it by 24.0, we will get 21,415896 where "21" is my hours value.

I've found some information on how to calculate this variant time on your own here: http://doxygen.reactos.org/df/d85/variant_8c_source.html - (in the "VarUdateFromDate" function)

It looks like variant time is capable of handling milliseconds, it's just functions like "VariantTimeToSystemTime" ignores them (maybe for the lack of precision reasons?). Function just rounds the milliseconds, adjusting the date-time forward if needed. (So in case we have input time "21:24:57.567", output time will be "21:24:58".

Found some interesting material here: http://www.codeproject.com/Articles/17576/SystemTime-to-VariantTime-with-Milliseconds - "SystemTime to VariantTime with Milliseconds".



回答2:

The date/time format in variant is identical to the date/time format in Excel.

Here is a short view how it is calculated: The part before the decimal separator specifies the day and the part after the decimal separator specifies the time.

The base of the format is 1900-01-01 00:00:00 with the value 1. So 1900-01-02 00:00:00 has the value 2, snd so forth, with one litte exception: The value 60 represents the date 1900-02-29, which didn't exist (1900 was no leapyear).

Values >= 0 and < 1 specify times without date relation. Values smaller than 0 are undefined.

The time is simply divided to days. Hour / 24, minute / 24 / 60, second / 24 / 60 / 60.

Information about the time zone is not saved.

Milliseconds are usually not used, but could be stored.