Datum
-
Hallo, kann mir jemand sagen, wie ich das aktuelle Jahr herausbekomme und in einer Variablen speichern kann?
-
Benutz doch mal die Suche...
-
Versuchs mal hiermit:
#include <stdio.h>
#include <sys/timeb.h>
#include <time.h>void main( void )
{
struct _timeb timebuffer;
char *timeline;_ftime( &timebuffer );
timeline = ctime( & ( timebuffer.time ) );printf( "The time is %.19s.%hu %s", timeline, timebuffer.millitm, &timeline[20] );
}MFG
-
Na ja in C++ wäre es dann halt so:
void get_time() { time_t aktuellezeit = time(NULL); tm *datum = localtime(&aktuellezeit); int stunden = datum->tm_hour; int minuten = datum->tm_min; int sekunden = datum->tm_sec; cout<<"Die aktuelle Uhrzeit lautet "<<stunden<<":"<<minuten<<":"<<sekunden<<" !"; }
-
Verdammt ich sollte mal bessser lesen
Na ja für das Datum einfach die Funktion umändern, habs mal für dich gemacht:
// void get_date() //////////////// void get_date() { time_t aktuellezeit = time(NULL); tm *datum = localtime(&aktuellezeit); int tag = datum->tm_mday; int monat = datum->tm_mon+1; int jahr = datum->tm_year+1900; cout<<"Das aktuelle Datum lautet "<<tag<<"."<<monat<<"."<<jahr<<" !"; }