5 Replies - 9796 Views - Last Post: 29 August 2012 - 02:05 AM Rate Topic: -----

#1 leniom_7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 03-July 10

get system's current date and time

Posted 29 August 2012 - 12:48 AM

I need to find the current date and time for use it in a function, not display it. Everything I found so far just displays the current date and time , and will not let me use it to do my calculation. If I can find out time and date separately would also work.
Is This A Good Question/Topic? 0
  • +

Replies To: get system's current date and time

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3553
  • View blog
  • Posts: 11,014
  • Joined: 05-May 12

Re: get system's current date and time

Posted 29 August 2012 - 01:27 AM

Your google-fu needs some help. Here's what I found with the keywords: "C++ date time":
http://www.cplusplus...clibrary/ctime/

Which unfortunately actually C. The real C++ functions are here:
http://en.cppreferen...om/w/cpp/chrono
Was This Post Helpful? 0
  • +
  • -

#3 Salem_c  Icon User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 1655
  • View blog
  • Posts: 3,133
  • Joined: 30-May 10

Re: get system's current date and time

Posted 29 August 2012 - 01:27 AM

gmtime() or localtime()
Was This Post Helpful? 0
  • +
  • -

#4 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 770
  • View blog
  • Posts: 2,249
  • Joined: 20-March 10

Re: get system's current date and time

Posted 29 August 2012 - 01:29 AM

Hi,

there is also _strdate and _strtime in ctime

#include <iostream>
#include <ctime>

int main ()
{
  char date [10];
  _strdate(date);
  std::cout<<"Current Date is: "<<date<< std::endl;

  char time [10];
  _strtime(time);
  std::cout<<"Current Time is: "<<time<< std::endl;
  return 0;
}


Was This Post Helpful? 0
  • +
  • -

#5 leniom_7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 03-July 10

Re: get system's current date and time

Posted 29 August 2012 - 01:47 AM

[quote name='Skydiver' date='29 August 2012 - 01:27 AM' timestamp='1346228836' post='1692555']
Your google-fu needs some help. Here's what I found with the keywords: "C++ date time":
http://www.cplusplus...clibrary/ctime/

Which unfortunately actually C. The real C++ functions are here:
http://en.cppreferen...om/w/cpp/chrono
[I said I need second , minute and hour ! and don't want to cout it !!!! ]
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3553
  • View blog
  • Posts: 11,014
  • Joined: 05-May 12

Re: get system's current date and time

Posted 29 August 2012 - 02:05 AM

I don't see anyplace in your post #1 that you needed second, minute, and hour.

And there is no requirement for you to output values using cout. The sample code was just there to demonstrate retrieving the time and printing it out.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1