Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.
int64 i64 = 0;
memcpy(&i64, &rtcvar, 6); // copy 6 lower bytes
time_t seconds = (time_t)(i64>>15);
time_t tt = time(NULL);
struct tm * stm = localtime(seconds);
void calcDateTime(long seconds, long hours_to_gm, long * date, long * time)
{
long daysmonth[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
long secs_per_year = 365 * 24 * 3600;
long secs_per_month = 31 * 24 * 3600;
long year = 1970;
long month = 1;
long day = 1;
long hours = 0;
long minutes = 0;
long leap = 0 ;
// adjust seconds to localtime
seconds -= hours_to_gm * 3600;
// year
for ( ; seconds > secs_per_year; ++year, seconds -= secs_per_year)
{
leap = ((year)%4 == 0 && ((year%100 != 0) || (year%400 == 0)))? 1 : 0;
secs_per_year = (365 + leap) * 24 * 3600;
}
// month
leap = ((year)%4 == 0 && ((year%100 != 0) || (year%400 == 0)))? 1 : 0;
daysmonth[2] = (leap)? 29 : 28;
for ( ; seconds >= secs_per_month; ++month, seconds -= secs_per_month)
{
secs_per_month = daysmonth[month]*24*3600;
}
// day
day = (seconds / (24 * 3600) ) + 1;
seconds = seconds % (24 * 3600) ;
hours = seconds / 3600;
seconds = seconds % 3600;
minutes = seconds / 60;
seconds = seconds % 60;
*date = year * 10000 + month * 100 + day;
*time = hours * 10000 + minutes * 100 + seconds;
}
void calcSeconds(long date, long time, long hours_to_gm, long * seconds)
{
long daysmonth[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
long year = date/10000;
long month = (date%10000)/100;
long day = date%100;
long hours = time/10000;
long minutes = (time%10000)/100;
long leap = ((year)%4 == 0 && ((year%100 != 0) || (year%400 == 0)))? 1 : 0;;
*seconds = time%100 + minutes * 60 + (hours + hours_to_gm) * 3600 + (day - 1) * 24 * 3600;
// month
daysmonth[2] = (leap)? 29 : 28;
for ( month = month-1; month > 0; --month)
{
*seconds += daysmonth[month] * 24 * 3600;
}
// year
for (year = year-1; year >= 1970; --year)
{
leap = ((year)%4 == 0 && ((year%100 != 0) || (year%400 == 0)))? 1 : 0;
*seconds += (365 + leap) * 24 * 3600;
}
}
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.