0

im new to c++. im trying to create a function to get the systemtime every 1 minute and store it in a variable. im able to display the time using the time.h file. the problem is i dont know how to call the function every 1 minute and assign it to the variable and display the time. any suggestions will be of immense help. im using unix (NOT WINDOWS).

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by siddhant3s
0

Well if you are using time.h which should be ctime in C++, then you can simple calculate when the next time a minute has passed so says its currently 12:31 then you can add 1 to that and check to see if the systemtime matches or is greater than it, if so display the time and then add one to the current time.

Chris

0

im able to display the current date and time using this code, but how do i display the updated time , every 1 minute ... any suggestions ?

# include <stdio.h>
# include <time.h>
int main()
{
printf("hello world\n");
time_t tim=time(NULL);
tm *now=localtime(&tim);
int a[3],b[3],c;
a[2]=now->tm_year+1900;
a[1]=now->tm_mon+1;
a[0]=now->tm_mday;
b[0]=now->tm_hour;
b[1]=now->tm_min;
b[2]=now->tm_sec;
c=now->tm_wday;
for(int i=0;i<3;i++)
{
printf("%d-",a[i]);
}
printf("\n");
for(int j=0;j<3;j++)
{
printf("%d:",b[j]);
}
printf("\nthe day is - %d",c);
}

Edited by mike_2000_17: Fixed formatting

0
while(displaying):
   if 1 min past:
      display time
   else:
      do nothing
loop

Also is this C or C++ code, it looks to me like C, yet you are in a C++ forum. Either way it is buggy.

Chris

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.