Subject: RE: Date/Time Value from Milliseconds using LotusScript Only
Nonsense. Solving the problem is simply a matter of knowing what you’re dealing with. The “milliseconds” the original poster is talking about is relative to something: start of day (midnight) of January 1, 1970, and at least in the case of JavaScript, that epoch time is GMT.
LotusScript Date variants are just Doubles with an “I’m a date-time” flag set. The number stored is the number of days and fraction of a day since the LS/VB epoch, which is midnight (start of day), December 31, 1899. The integer portion of the number is the number of days, and the decimal is the time represented as a fraction of the day.
One merely needs to create the JS epoch as a Date Variant, then add the number of days the millisecond value represents. There is one tiny little hitch in the plan, though, and that’s that a Date Variant is blind when it comes to time zones. A NotesDateTime object is not better – you can read a GMT time, but you can’t write one. However, you can READ a time zone from a NotesDateTime.
Function JSMillisecondsToLSDate(millis As Double) As Variant
Dim ndt As NotesDateTime
Dim zoneOffset As Integer
Dim jsEpochDouble As Double, adjustedEpochDouble As Double, millisDateDouble As Double
%REM
JavaScript millisecond values are based on GMT
but writable LotusScript date/time values are local.
We need to know the local timezone offset from GMT,
and for that we need a NotesDateTime object
with both date and time components
%END REM
Set ndt = New NotesDateTime(Now)
zoneOffset = ndt.TimeZone
'The JavaScript epoch is midnight (day start) January 1, 1970 GMT
jsEpochDouble = Cdbl(Datenumber(1970,1,1))
'Adjust epoch to local time
adjustedEpochDouble = jsEpochDouble - (zoneOffset/24)
'There are 86400000 milliseconds in a day
millisDateDouble = adjustedEpochDouble + (millis / 86400000)
JSMillisecondsToLSDate = Cdat(millisDateDouble)
End Function
Getting the returned value as text is easily done to whatever spec you need using the LS Format function.