time() function returns date in 1970

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
carlosedp
Posts: 21
Joined: Tue Jun 19, 2007 4:20 am
Location: Sao Paulo / Brazil

time() function returns date in 1970

Post by carlosedp »

I'm working on the port of Stackless for PSP.. I found out a problem where I could replicate in a small C app. When calling the time() function, it returns me the time in GMT but the date is 01/01/1970.

If I substituted the time() function by sceKernelLibcTime() function, it returns me the correct time and date but in GMT.

Reading the forums I saw that if I call tzset(), It would grab PSP timezone and apply it correctly but its not working... even calling tzset() the time is still in GMT.

Here is the small case:

Code: Select all

int main() {
    pspDebugScreenInit();
    SetupCallbacks();
    tzset&#40;&#41;;                     // <- does nothing....
    printf&#40;"Hello World"&#41;;
    time_t now;
    //now = time&#40;NULL&#41;;                     // <-date in 01/01/1970 and GMT time
    now = sceKernelLibcTime&#40;NULL&#41;;   // -< date correct but time in GMT
    printf&#40;"Started %s\n", ctime&#40;&now&#41;&#41;;
    sceKernelSleepThread&#40;&#41;;
    return 0;
    &#125;
I'm using cygwin on windows XP, I have installed it from scratch and downloaded the toolchain from oopo website (psptoolchain-20070606.tar).

Thanks for any help,

Carlos
[/code]
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Re: time() function returns date in 1970

Post by sakya »

Hi! :)

This works well for me:

Code: Select all

	struct tm * ptm;
	time_t mytime;
	tzset&#40;&#41;;
	time&#40;&mytime&#41;;
	ptm = localtime&#40;&mytime&#41;;
	pspDebugScreenSetXY&#40;0, 0&#41;;
	pspDebugScreenPrintf&#40;"%2.2d/%2.2d/%4.4d %2.2d&#58;%2.2d",ptm->tm_mday, ptm->tm_mon + 1, ptm->tm_year + 1900, ptm->tm_hour,ptm->tm_min&#41;;
Ciaooo
Sakya
carlosedp
Posts: 21
Joined: Tue Jun 19, 2007 4:20 am
Location: Sao Paulo / Brazil

Post by carlosedp »

Same problem here... 01/01/1970 ... and time in GMT (here i'm GMT-3).

Maybe I have a problem in my environment... dunno because I have installed it all from scrach following the wiki.

If you could point me out what to check....

Thanks,

Carlos
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Post by sakya »

Ciao! :)
carlosedp wrote:If you could point me out what to check....
Sorry, I don't know. You need someone more expert. :)

I can tell you I'm using the devkit from xorloser on Windows XP.
http://xorloser.com/PSPDevWin32.zip

The code I posted works fine for me (GMT+1).

Ciaooo
Sakya
carlosedp
Posts: 21
Joined: Tue Jun 19, 2007 4:20 am
Location: Sao Paulo / Brazil

Post by carlosedp »

Thanks a lot Sakya, It was a problem in my environment... I substituted the PSPDEV tree in my cygwin install and the time() function returned the correct time and date.

Thanks a lot for pointing out.

Carlos
Post Reply