Getting the Current Date and Time


Mac OS X header: CoreServices/CoreServices.h
Mac OS 9 header: DateTimeUtils.h


Getting the Current Date and Time Functions
GetDateTime Obtains the current date-time information, expressed as the number of seconds elapsed since midnight, January 1, 1904.
GetTime Obtains the current date-time information, expressed as a date and time.
ReadDateTime Copies the date-time information from the clock chip into low memory.


GetDateTime

Carbon status: Supported

Obtains the current date-time information, expressed as the number of seconds elapsed since midnight, January 1, 1904.

void GetDateTime (
    UInt32 *secs
);
Parameter descriptions
secs

On return, the number of seconds elapsed since midnight, January 1, 1904.

Discussion

The low-memory copy of the date and time information is also accessible through the global variable Time.

If an application disables interrupts for longer than a second, the date-time information returned by the GetDateTime function might not be exact. The GetDateTime function is intended to provide fairly accurate time information, but not scientifically precise data.

Availability

Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 8.1 or later.


GetTime

Carbon status: Supported

Obtains the current date-time information, expressed as a date and time.

void GetTime (
    DateTimeRec *d
);
Parameter descriptions
d

On return, the fields of the date-time structure contain the current date and time.

Discussion

The GetTime function first calls the GetDateTime function to obtain the number of seconds elapsed since midnight, January 1, 1904. It then calls the SecondsToDate function to convert the number of seconds into a date and time.

As an alternative to using the GetTime procedure, you can pass the value of the global variable Time to the SecondsToDate function; a SecondsToDate(Time) function call is identical to a GetTime(d) function call.

If an application disables interrupts for longer than a second, the date-time information returned by the GetTime function might not be exact. The GetTime function is intended to provide fairly accurate time information, but not scientifically precise data.

Availability

Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 8.1 or later.


ReadDateTime

Carbon status: Supported

Copies the date-time information from the clock chip into low memory.

OSErr ReadDateTime (
    UInt32 *time
);
Parameter descriptions
time

On return, the current time expressed as the number of seconds elapsed since midnight, January 1, 1904.

function result

A result code. If the clock chip cannot be read, ReadDateTime returns the clkRdErr result code. The operation might fail if the clock chip is damaged. Otherwise, the function returns the noErr result code.

Discussion

System software uses this function at startup time. Your application should never need to use this function.

The low-memory copy of the date and time information is accessible through the global variable Time.

Availability

Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 8.1 or later.


© 2001 Apple Computer, Inc. (Last Updated July 17, 2001)