com.dalsemi.system
Class Clock

java.lang.Object
  |
  +--com.dalsemi.system.Clock

public class Clock
extends java.lang.Object

This class provides access to the TINI Real-Time clock. The methods support setting and getting the clock values (milliseconds since Jan 1, 1970).

Usage

The getTickCount() method returns the same value as java.lang.System.currentTimeMillis() and is included for completeness. Programmers should use System.currentTimeMillis() for correct Java compatibility.


      ...
      long time = com.dalsemi.system.Clock.getTickCount();
      System.out.println(new java.util.Date(time));
      ...
 

The following code sets the TINI Real-Time clock to October 4, 2000 at 1:43 in the afternoon.


      ...
      java.util.Date myDate = new java.util.Date(2000-1900, 10-1, 4, 13, 43, 00);
      long millis = myDate.getTime();
      com.dalsemi.system.Clock.setTickCount(millis);
      ...
 

Note that the time printed will probably not be 1:43 PM. The time stored is for GMT. On a TINI with Central Standard Time as the default TimeZone, this program prints out:

    TINI /> java clockdemo.tini
    Wed Oct 4 08:43:59 CST 2000
 

which is correct because CST during Daylight Savings Time (CDT) is 5 hours behind GMT.


Method Summary
static long getTickCount()
          Get the current time in milliseconds since midnight Jan 1, 1970, UTC.
static void setTickCount(long millis)
          Set the current time from a value in milliseconds since Jan 1, 1970, UTC.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getTickCount

public static long getTickCount()

Get the current time in milliseconds since midnight Jan 1, 1970, UTC. The value returned is suitable to be used in calls to Java classes such as java.util.Date and java.util.Calendar.

Note: It it highly recommended not to call this method, and instead use java.lang.System.currentTimeMillis() to insure Java portability.

Returns:
number of milliseconds since midnight, Jan 1, 1970 UTC
See Also:
setTickCount(long)

setTickCount

public static void setTickCount(long millis)

Set the current time from a value in milliseconds since Jan 1, 1970, UTC.

This method is not written to handle negative values for millis. Note, the underlying hardware clock may only store the 2 least significant digits of the year. Subsequent calls to getTickCount() will add these 2 digits to the year 2000 to come up with the current year. If you call setTickCount() with a value for a date in 1999, then getTickCount() may return you a value for a date in 2099.

Parameters:
millis - number of milliseconds since midnight, Jan 1, 1970 UTC
See Also:
getTickCount()


Also see:
o TINI 1.11 API, Optional Modules
o TINI Home Page
o 1-Wire API

Last update Fri Jan 24 12:06:43 CST 2003
Используются технологии uCoz