显示系统时间

  1. #include <iostream> 
  2. #include <time.h>
  3. using namespace std ; 
  4. class ShowDateClass
  5. {
  6. public:
  7.     void ShowDate(void)
  8.     {
  9.         time_t curtime=time(0); 
  10.         tm tim =*localtime(&curtime); 
  11.         int year,month,day; 
  12.         
  13.         year=tim.tm_year+1900; 
  14.         month=tim.tm_mon+1; 
  15.         day=tim.tm_mday; 
  16.         cout<< year <<"-"<< month <<"-"<< day <<endl ;
  17.     }
  18. };
  19. int main() 
  20. {  
  21.     ShowDateClass showdate ; 
  22.     showdate.ShowDate();
  23.     return 0; 
 

你可能感兴趣的:(显示系统时间)