Du hast nicht geschrieben, ob Du Basic oder C verwendest?
Für C gibt es "seit langem" eine sehr Elegante Lösung in time.h.
(Etwas ähnliches - ich habe es für meine Zwecke ein bisschen verkürzt.)
Karoly
-----------------------------------------------------------------------
struct tm
{
int tm_year; /* Year since 1900 */
unsigned char tm_mon; /* Month. [0-11] */
unsigned char tm_mday; /* Day. [1-31] */
unsigned char tm_hour; /* Hours. [0-23] */
unsigned char tm_min; /* Minutes. [0-59] */
unsigned char tm_sec; /* Seconds. [0-60] */
};
typedef unsigned long time_t;
#define between(a, c, z) \
((unsigned)((c) - (a)) <= (unsigned)((z) - (a)))
#define LEAP_YEAR(year) ((year%4)==0)
char monthDays[]={31,28,31,30,31,30,31,31,30,31,30,31};
// convert broken time to calendar time (seconds since 1970)
time_t mktime(struct tm *timeptr) {
int year=timeptr->tm_year+1900, month=timeptr->tm_mon, i;
long seconds;
// seconds from 1970 till 1 jan 00:00:00 this year
seconds= (year-1970)*60L*60*24*365;
// add extra days for leap years
for (i=1970; i<year; i++) {
if (LEAP_YEAR(i)) {
seconds+= 60L*60*24;
}
}
// add days for this year
for (i=0; i<month; i++) {
if (i==1 && LEAP_YEAR(year)) {
seconds+= 60L*60*24*29;
} else {
seconds+= 60L*60*24*monthDays[i];
}
}
seconds+= (timeptr->tm_mday-1)*60L*60*24L;
seconds+= timeptr->tm_hour*60L*60;
seconds+= timeptr->tm_min*60L;
seconds+= timeptr->tm_sec;
return seconds;
}