How to get Time in seconds??

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

Moderators: cheriff, TyRaNiD

Post Reply
Compozitor
Posts: 2
Joined: Sun Feb 25, 2007 3:18 am

How to get Time in seconds??

Post by Compozitor »

Sorry for maybe lame question. I'm using Old School library, and i'm newbie at C\C++ programming. And there is so little examples for psp SDK, and i still cannot properly read header files.

PLease help me. I would be very greatfull for function that will return time in sec. Thx!
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

time_t t = time(NULL); perhaps ? :)
Compozitor
Posts: 2
Joined: Sun Feb 25, 2007 3:18 am

Post by Compozitor »

Thank you! Sorry one more time. Can someone write here how to get milliseconds?? Thx!
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

these posts only create the spiraling effect
you dont know how to get milliseconds now
then you need to know how to view contents of
a directory for a file browser or you might not
know how to sort filenames ...the point is that
this site is not here for rudimentary programming
exercises ...those things are best learnt somewhere
else where we ALL have learnt them ...from books
from online articles, tutorials of all natures ...so before
i will allow this spiraling to happen to you ...go do your
part in your understanding

go do some research :)
start of with the simple stuff and you will know
more questions and not more answers
http://www.cplusplus.com
10011011 00101010 11010111 10001001 10111010
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Post by Cy-4AH »

I have problem, there is code:

Code: Select all

        char str_today[128];
        time_t now;
        tm *today;
        time(&now);
        today = localtime(&now);
        timeval tv;
        timezone tz;
        sceKernelLibcGettimeofday(&tv, &tz);
        pspDebugScreenSetXY(0,0);
        strftime(str_today, sizeof(str_today), "%d.%m.%Y %H:%M:%S %c %X", today);
        printf("%s\n%s\n", str_today, ctime(&now));
        printf("%d %d\n", tz.tz_minuteswest, tz.tz_dsttime);
So, the problem is that localtime don't correct time to my local time and tz.tz_minuteswest is equals to 0;
But I know that in psp settings GMT+2.00 and main meny showing me right time.
Of course I can add 2 hours, but it's not beatifully.
adrahil
Posts: 274
Joined: Thu Mar 16, 2006 1:55 am

Post by adrahil »

/me hangs himself on to a tree...
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Post by Cy-4AH »

adrahil wrote:/me hangs himself on to a tree...
adrahil, plz, don't kill yourself. I had found already, that instead using time.h and time() we mast use psprtc.h and sceRtcGetCurrentClockLocalTime();
I'll delete this post.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Perhaps when people ask questions like "how do I get the time?" we should just always post this:

http://psp.jim.sh/pspsdk-doc/
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Calm down, guys, it was a legit question, even though it's been answered on these forums before.

Cy-4AH, you have to call "tzset()" to set up the timezone in newlib.
It will initialize it automatically using the PSP's timezone settings.

See this post for more details: http://forums.ps2dev.org/viewtopic.php? ... ight=tzset
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Post by Cy-4AH »

J.F. wrote:Perhaps when people ask questions like "how do I get the time?" we should just always post this:

http://psp.jim.sh/pspsdk-doc/
J.F.Of course I use pspsdk-doc. Do you think that I just imagened functions time and localtime and they magicaly begin work?
If you look in pspsdk-doc at time.h you'll see that there is nothing usefull, only functions prototypes and function tzset not even mentioned Don't believe? . Look http://psp.jim.sh/pspsdk-doc/time_8h.html. So I looked in MSDN and didn't noticed tzset :)
May be you should add to sdk: "Before using localtime call tzset to set your local zone".
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Cy-4AH wrote:
J.F. wrote:Perhaps when people ask questions like "how do I get the time?" we should just always post this:

http://psp.jim.sh/pspsdk-doc/
J.F.Of course I use pspsdk-doc. Do you think that I just imagened functions time and localtime and they magicaly begin work?
If you look in pspsdk-doc at time.h you'll see that there is nothing usefull, only functions prototypes and function tzset not even mentioned Don't believe? . Look http://psp.jim.sh/pspsdk-doc/time_8h.html. So I looked in MSDN and didn't noticed tzset :)
May be you should add to sdk: "Before using localtime call tzset to set your local zone".
Notice I said questions LIKE that one, not that one itself. :)

And it's good you use the docs... just be sure to mention that along with the question so that people know you aren't just being lazy. :D
Post Reply