to display current date and time

simple code to display the current date and time in c++

Page 1 of 1

1 Replies - 29892 Views - Last Post: 02 January 2008 - 10:28 AM Rate Topic: -----

#1 vinu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-January 08

to display current date and time

Posted 02 January 2008 - 04:13 AM

Hi,
I need a simple code to display the current date and time in c++.I am new to c++.please do help me.

Thanks.
Is This A Good Question/Topic? 0
  • +

Replies To: to display current date and time

#2 tralfas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-January 08

Re: to display current date and time

Posted 02 January 2008 - 10:28 AM

View Postvinu, on 2 Jan, 2008 - 04:13 AM, said:

Hi,
I need a simple code to display the current date and time in c++.I am new to c++.please do help me.

Thanks.



#include <iostream> 
#include <time.h>
using namespace std;

int main()
{
	time_t tim;  //create variable of time_t
	time(&tim); //pass variable tim to time function 
	cout << ctime(&tim); // this translates what was returned from time() into a readable format

	return 0;
}


This post has been edited by tralfas: 02 January 2008 - 10:30 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1