Here is a way to get the date and time of the palm. This function
writes the date and time to two globals, Currentdate and Currenttime
(both are Char strings).
static void GetCurrentDate()
{
DateTimeType ct;
static char ztime[32], zdate[32]; // Arrays for date and time
static char ldate[32]; // Array for the other date used
// getting the
year
SystemPreferencesType sysPrefs;
UInt8 test = 0;
// Get system preferences
PrefGetPreferences(&sysPrefs);
ztime[0] = 0; zdate[0] = 0; ldate[0]=0;
// Get time/date structure
TimSecondsToDateTime(TimGetSeconds(),&ct);
// Get two different date formats
DateToAscii(ct.month,ct.day,ct.year, dfYMDLongWithDot, ldate);
test = StrLen( ldate );
// I like to pad a zero into dates to make parsing easier.
if ( ldate[6] == '.' ) // date is in either yyyy.m.dd or yyyy.m.d
{
Currentdate[0] = '0';
Currentdate[1] = ldate[5];
if ( test < 9 && ldate[6] == '.' )
{
Currentdate[2] = '0';
Currentdate[3] = ldate[7];
}
else
{
Currentdate[2] = ldate[7];
Currentdate[3] = ldate[8];
}
}
else
{
Currentdate[0] = ldate[0];
Currentdate[1] = ldate[1];
if ( test < 10 && ldate[7] == '.' ) // date is in yyyy.mm.d
{
Currentdate[2] = '0';
Currentdate[3] = ldate[8];
}
else // date is in yyyy.mm.dd
{
Currentdate[2] = ldate[8];
Currentdate[3] = ldate[9];
}
}
Currentdate[4] = ldate[0];
Currentdate[5] = ldate[1];
Currentdate[6] = ldate[2];
Currentdate[7] = ldate[3];
Currentdate[8] = '\0';
// Get time
TimeToAscii( ct.hour, ct.minute, tfColonAMPM, ztime);
StrCopy( Currenttime, ztime );
}
In this function, I changed the date time format around by
moving characters around (that's why it's as long as it is).
As for getting the time separately, you have to kind of hack around
to get it fairly close to actual time. I think you can count nilEvents
or something...but remember, what you're doing isn't really multithreaded,
so you will need to implement some sort of timesharing mechanism if you
want to do other tasks concurrently. However, if you search the archives,
you will probably find something adequate for your needs.
-Rus
>-----Original Message-----
>From: Farzin Ashraghi [mailto:[EMAIL PROTECTED]]
>Sent: Friday, July 28, 2000 9:46 AM
>To: Palm Developer Forum
>Subject: Date and Time
>
>
>Hi!
>
>Is there some way to calculate the time elapsed independently
>of the hour
>based system? I don't know, maybe through counting ticks. I
>was reading the
>last case where was necesary to know the exact time of some
>events in the
>day, protected against the hour changes by the user, but it is very
>difficult to prohibit the user to change the time and maybe he
>needs do it.
>
>Another question, yes, it must be a silly question, but how
>can I get the
>date and time of the Palm?
>
>Thank you!
>Farzin
>
>
>--
>For information on using the Palm Developer Forums, or to
>unsubscribe, please see http://www.palmos.com/dev/tech/support/forums/
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/