Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,990 questions

51,935 answers

573 users

How to get localtime in C++

2 Answers

0 votes
#include <iostream>
#include <ctime>

using std::cout;
using std::endl;

int main()
{
	time_t t = time(NULL);   
	tm* now = std::localtime(&t);

	cout << now->tm_mon + 1 << '/' << now->tm_mday << "/" << now->tm_year + 1900 << endl;
	cout << now->tm_sec << ':' << now->tm_min << ":" << now->tm_hour << endl;

	return 0;
}


/*
run:

6/2/2018
6:53:18

*/

 



answered Jun 2, 2018 by avibootz
0 votes
#include <iostream>
#include <ctime>

using std::cout;
using std::endl;

int main()
{
	time_t tm;
	struct tm *p;

	time(&tm);
	p = localtime(&tm);

	cout << asctime(p) << endl;
	
	return 0;
}


/*
run:

Sat Jun  2 18:55:43 2018

*/

 



answered Jun 2, 2018 by avibootz

Related questions

2 answers 165 views
165 views asked Jun 2, 2018 by avibootz
1 answer 169 views
...