Controlla che il valore restituito da "time" sia diverso da "(time_t) -1".
Quando stampi l'indirizzo di "t", non usare "%d", ma "%p":
Codice PHP:
/*
* Thu Nov 15 15:02:39 EET 2007
* Compiled and tested with:
* i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5367)
*
* output:
time_t t:0xbfffecc0
'2007-11-15 15:03:27';
*/
#include <time.h>
#include <stdio.h>
int main (void){
char temp[3000];
time_t t;
struct tm *now;
if ((time_t) -1 != time(&t)){
printf("time_t t:%p\n", &t);
now = localtime(&t);
sprintf (temp, "'%04d-%02d-%02d %02d:%02d:%02d';\n", now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec);
printf (temp);
}
return 0;
}