Click here to Skip to main content
15,916,683 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi,

I am trying to write a program that has to perform deduction of 5 minute from current system. How this can be achieved in vc++...

regards,
sanath
Posted
Comments
André Kraak 28-Sep-11 3:54am    
What is it you exactly want? Do you mean you want to change the system time, as you might do through the configuration screen?

C++/CLI
DateTime ^ dt;
dt = DateTime::Now.AddMinutes(-5);
Console::WriteLine(L"5 minutes ago : {0}", dt);
 
Share this answer
 
Comments
sanathbt 30-Sep-11 7:27am    
is this for c++? If yes tell me which header i have to use...
CPallini 30-Sep-11 8:23am    
It is C++/CLI, as specified in your question's tag.
#include <stdio.h>
#include<iostream.h>
#include <time.h>
#include<conio.h>

int main ()
{

time_t rawtime;
struct tm * timeinfo;
int min, hr,sec;

time ( &rawtime );
timeinfo = localtime ( &rawtime );

printf ( "Current local time and date: %s", asctime (timeinfo) );
min=timeinfo->tm_min;
hr=timeinfo->tm_hour;
// sec=timeinfo->tm_sec;


min=min-5;

if(min<0)
{
min=min+60;
hr--;
cout<<"\n After deducting 5 min new time is "<<hr<<":"<<min;
}
else
{
cout<<"\n After deducting 5 min new time is "<<hr<<":"<<min;

}

getch();
return 0;

}

this is complete code
 
Share this answer
 
in c++ you can retrieve system time by __TIME__ and you can store this time in a variable

char code my_time[] = "Compile Time = " __TIME__;


now you can get the values and do what you want to do

best of luck for the rest.
 
Share this answer
 
Comments
sanathbt 30-Sep-11 7:42am    
I am not getting the remaining logic only... I tried my logic its giving -ve values for some input.
If you know the logic, give me suggestion.... That logic to work for everything like leap year etc....
Mithun Thakur From NICE Computers 30-Sep-11 23:50pm    
can you explain that what exactly you want to do? is it do you want to read system time and want to less 5 min from it or you want to set System Time
sanathbt 3-Oct-11 7:18am    
Now I am reading the system time by using time.h . I want to subtract 5 minutes from that time...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900