PDA

View Full Version : Time and Date n C++



Sly Rudolf
August 19th, 2009, 05:52 AM
Hi,

I am writing a C++ program (on Ubuntu) and was wondering how to get the time and date (from real life) into the program so I can use it to compare dates form data to.

Any help or advice on where to look would be most appreciated.

gtr32
August 19th, 2009, 06:05 AM
http://www.cplusplus.com/reference/clibrary/ctime/time/

dwhitney67
August 19th, 2009, 10:10 AM
http://www.boost.org/doc/libs/1_37_0/doc/html/date_time.html

MindSz
August 19th, 2009, 06:33 PM
This is small C program that prints out current date

#include <stdio.h>
#include <time.h>
#include<string.h>

int main (){

time_t date_temp; // Stores seconds elapsed since 01-01-1970
struct tm *date_format; // Saves in Date format
char date_out[25]; // Output string

time(&date_temp);
date_format = localtime(&date_temp);
strftime(date_out, 25, "%Y-%m-%d, %H:%M:%S", date_format);

printf ("\nDate: %s\n\n", date_out);

return 0;
}

Sly Rudolf
August 20th, 2009, 04:27 AM
Cheers. Thanks