TimeStamp Class

David T. Lewis lewis at mail.msen.com
Fri Apr 8 01:26:53 UTC 2005


On Thu, Apr 07, 2005 at 03:10:47PM -0400, Daniel Salama wrote:
> I'm trying to get the difference of two TimeStamps objects and the best 
> accuracy I get is "asSeconds". When I try asMilliSeconds or 
> asNanoSeconds, the result is simply padded with 0s. Is there a better 
> way to get higher degree of accuracy? Maybe I'm just using the wrong 
> classes. For example:
> 
> epoch := TimeStamp date: (Date readFromString: '01-01-1970') time: 
> (Time new).
> Transcript clear.
> 1 to: 20 do: [:i|
> 	Transcript cr; show: (((TimeStamp date: (Date today) time: (Time now)) 
> - epoch) asMilliSeconds)
> ].
> 
> The idea behind is to get the number of milli seconds since the Epoch. 
> Is there a better way to do this?

If you are actually interested in elapsed time since the (Posix) epoch,
take a look at TimeZoneDatabase on Squeak Map. Class PointInTime represents
time since the epoch as unlimited precision ScaledDecimal (a plugin
is provided to help with this).

Left to its own devices Squeak will give you misleading results, because
it determines time based on local time, which moves things around in odd
ways when daylight savings time transitions or leap second transitions occur.

If you are just trying to get millisecond resolution for fairly short
time durations, then see Time class>>primMillisecondClock.

Dave





More information about the Squeak-dev mailing list