C ++程序从当前系统扣除5分钟 [英] c++ program to deduct 5 minute from the current system
本文介绍了C ++程序从当前系统扣除5分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个程序,该程序必须从当前系统中扣除5分钟.如何在vc ++中实现这一目标...
问候,
sanath
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
推荐答案
DateTime ^ dt;
dt = DateTime::Now.AddMinutes(-5);
Console::WriteLine(L"5 minutes ago : {0}", dt);
#include< stdio.h>
#include< iostream.h>
#include< time.h>
#include< conio.h>
int main()
{
time_t rawtime;
struct tm * timeinfo;
int min,hr,sec;
时间(& rawtime);
timeinfo =当地时间(& rawtime);
printf(当前本地时间和日期:%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减去5分钟后,新时间为"<< hr<:"<< min;
}
其他
{
cout<"\ n减去5分钟后,新时间为"<< hr<:"<< min;
}
getch();
返回0;
}
这是完整的代码
#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
在c ++中,您可以通过__TIME__检索系统时间,并且可以将此时间存储在变量中
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.
这篇关于C ++程序从当前系统扣除5分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文