Link to home
Start Free TrialLog in
Avatar of Jammer1224
Jammer1224

asked on

Urgent: Time and Date calculations.

Hi,

Since I am creating (atleast trying) a trail version of my software, I am concerned about the time and date parameters.
The user can simply turn his bios or windows clock back and still use the software if using time() or any other functions which are provided by Borland.

To avoid this I decided to get the current time from the time servers.
My current result is the current time (year,month,day,hour,minute,second) stored in different integers.

The main problem of mine is the calculation if the year has changed. For example if the program was started using at 21 of December, 2008 and the current date is 2 January 2009 and the trail period is 30 days the program should still stay active. Also there is alot of problems with february which has a different day count every 4 years and so on. Also every second month has different ammount of days in  it,also daylight saving and other factors.

Well the daylight saving is the last thing to worry about. I'll give away that one free hour :).

I could use time(0) difftime() functions to calculate the correct difference (I hope that they will be correct), but first I have to understand how to convert the current date and the trail start date to the format which uses 1970 01 01 00:00 as the start of calculation. Then understand how to turn the difference of time since that date to seconds. Calculating it would also be a problem because of the February.

Since the program will only be a three day trail the miscalulations of february could turn up a disaster which could end up a 20 or more day trail instead of 3.

Also readed about the Julian Time format, but I'm not sure if it suits my needs.

I saw an object called DateTime in .NET which would solve all my problems. Maby there is something similar in C++/Borland C++?
Avatar of ozo
ozo
Flag of United States of America image

#include <time.h>

     double
     difftime(time_t time1, time_t time0);

     char *
     asctime(const struct tm *tm);

     struct tm *
     localtime(const time_t *clock);

     struct tm *
     gmtime(const time_t *clock);

     time_t
     mktime(struct tm *tm);

     time_t
     timegm(struct tm *tm);

     size_t
     strftime(char * restrict buf, size_t maxsize,
         const char * restrict format, const struct tm * restrict timeptr);


Avatar of Jammer1224
Jammer1224

ASKER

I guess you didn't read the whole post.
all functions require a parameter of time_t.
and time_t = time since 1970 01 01 00:00 in seconds.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Could have included an example.
Is there any particular example you'd want me to include?
I've managed to complete everything my self. Thanks.