Jahreszahl auslesen
-
Hallo!
ich muss die Jahreszahl auslesen. Mit der Date Funktion hab ich das auch hinbekommen, nur ich brauche die Jahreszahl 4 - ziffrig (also 2003 statt 03). Wie bekomme ich das hin?
-
#include <stdlib.h> #include <stdio.h> #include <time.h> int main() { time_t sec; struct tm* ctime; time( &sec ); ctime = localtime( &sec ); printf( "jahr: %d\n", ctime->tm_year + 1900 ); /* oder wenn du es als string willst: */ strftime( buf, 5, "%Y", ctime ); printf( "jahr: %s\n", buf ); }
schau dir mal die strftime funktion an, die bietet ne menge an optionen
um datumsangaben zu formatieren.
-
oops
-
danke für die Hilfe!!