Example |
#include <stdio.h>
#include "lib.h"
short GetWeekNumber( void )
{
unsigned long ulF, ulS, ulT;
unsigned long m, y, a;
unsigned long ulJDN;
struct date d = {0};
GetDate( &d );
a = (14UL - d.da_mon ) / 12UL;
y = d.da_year + 4800UL - a;
m = d.da_mon + (12UL*a) - 3UL;
ulJDN = d.da_day + (( 153UL * m + 2UL) / 5UL) + (365UL * y) + (y / 4UL) - (y / 100UL) + (y / 400UL) - 32045UL;
ulF = ( ulJDN + 31741UL - ( ulJDN % 7UL )) % 146097UL % 36524UL % 1461UL;
ulS = ulF / 1460UL;
ulT = (( ulF - ulS ) % 365UL) + ulS;
return (short)((ulT / 7UL) + 1UL);
}
void main( void )
{
struct date d = {0};
for(;;)
{
GetDate( &d );
printf("%02d-%02d-%04d\nWeek number %d\n", d.da_day, d.da_mon, d.da_year, GetWeekNumber() );
Delay( 250 );
}
}
|