Welcome! Log In Create A New Profile

Advanced

Getting the system time??

Posted by newlife 
Getting the system time??
May 18, 2010 12:11AM
Hi everyone, I want my app to have a built in clock (and an alarm clock, but I have sorted that bit), but cant figure out how to get the time from the system clock on the wii, is there a way to do this?? and how is it stored (seconds/milliseconds) and is there any way to get the date aswell? and what format is it in? (Day of the year-year or dd/mm/yy, or mm/dd/yy)

thanks for your help.
Re: Getting the system time??
May 18, 2010 12:15AM
to get the time try

int getTime()
{
return (gettime() / TB_TIMER_CLOCK) & 0x7FFFFFFF;
}

I'm afraid i'm cluless on the date, and if anyone has a better code for time please feal fre to correct me.



Edited 1 time(s). Last edit at 05/18/2010 10:59PM by dan3008.
Re: Getting the system time??
May 18, 2010 05:55AM
This is some code from my screenshot function, it uses a timestamp:
    char path[255];
    time_t now = time(NULL);
    struct tm *ti = localtime(&now);
    sprintf(path, "sd:/screenshot_%d%02d%02d%02d%02d%02d.png",
        ti->tm_year + 1900, ti->tm_mon + 1, ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec);
Re: Getting the system time??
May 18, 2010 10:45PM
Here's some info about how to get the date:
[www.cplusplus.com]

EDIT:
@dan3008: What the RGBA white for?



Edited 2 time(s). Last edit at 05/18/2010 10:46PM by diego_pmc.
Re: Getting the system time??
May 18, 2010 10:59PM
oops, didnt need that, that was used for printing the time, i must have forgotten to remove it when I got rid of the rest of my function.
Re: Getting the system time??
May 18, 2010 11:02PM
@dan3008, i'll try it, but i'm not overly hopefull, you havent said what libaries are needed.
@crayon same as above
@diego_pmc can you exsplain your code in a bit more detail please. :) thanks.
Re: Getting the system time??
May 19, 2010 12:35AM
It should be one of these:
#include <ogcsys.h>
#include <ogc/lwp_watchdog.h>
Re: Getting the system time??
May 19, 2010 11:32PM
ok, maby its just me but I cant seem to get it to work, keeps erroring, can someone tell me step by step how to do it. I've tried googleing but not found anything T_T
Re: Getting the system time??
May 20, 2010 11:26AM
Quote
newlife
ok, maby its just me but I cant seem to get it to work, keeps erroring, can someone tell me step by step how to do it. I've tried googleing but not found anything T_T
Your information is to limited to help you. Details about what you are doing and what the result is are required for assistance. Only thing we can say now is "if it's not working then you are doing something wrong" we cannot magically guess what you are doing wrong.
Re: Getting the system time??
May 20, 2010 02:40PM
I think what she wants is a step by step guide to get the system time and store it as intergers. Not specific advice about how to fix any ine problem. Please correct me if i'm worong.
Re: Getting the system time??
May 20, 2010 06:46PM
Here is a quick stab at explaining diego_pmc's linked code...

// Include standard library
#include 
// Include library with time functions
#include 
int main ()
{

  // Prepare a variable of type time_t called rawtime.
  // This is the native format for the time function.
  time_t rawtime;
  // Prepare a variable of type tm called timeinfo.
  // The time will be converted to this format which allows us to display it.
  struct tm * timeinfo;

  // Load the current time into the rawtime variable
  time ( &rawtime ); 
  // Converts the time from time_t type variable to tm type variable so that we can convert the time to string.
  // This function may also convert from GMT to local time zone (please, anyone, feel free to correct me if I am wrong)
  timeinfo = localtime ( &rawtime );
  // Converts the time to a string and prints it out
  printf ( "Current local time and date: %s", asctime (timeinfo) );
  
  return 0;
}



Edited 2 time(s). Last edit at 05/20/2010 06:52PM by LordAshes.
Re: Getting the system time??
May 22, 2010 02:43PM
Oh, excelelent. Thankyou soooooooooooo much loard ashes and diego_pmc. It makes alot more sense now. I wil post back if and when i get this working :D.
Re: Getting the system time??
May 23, 2010 10:26PM
Hang on a sec. This converts the time into a string. is it possable to keep it stored as a interger?
I ask this because i want to use the time to make a working allarm clock to include in my game.


is asctime (timeinfo) the interger?



Edited 1 time(s). Last edit at 05/23/2010 10:27PM by newlife.
Re: Getting the system time??
May 24, 2010 12:32AM
yes, timeinfo is the integer, while ascrime turns it into a string
Re: Getting the system time??
May 24, 2010 10:44PM
Thankyou

so could i use any interger i want as instead of time info? aslong as i declare it first? and then would it be useable just like a normal interger?
Re: Getting the system time??
May 25, 2010 12:26AM
Quote
newlife
Thankyou

so could i use any interger i want as instead of time info? aslong as i declare it first? and then would it be useable just like a normal interger?
Kinda, the timeinfo variable is a tm struct, which looks like this:
struct tm
{
  int	tm_sec;
  int	tm_min;
  int	tm_hour;
  int	tm_mday;
  int	tm_mon;
  int	tm_year;
  int	tm_wday;
  int	tm_yday;
  int	tm_isdst;
};
I you go timeinfo.tm_sec you would get the seconds in an integer. If you wanted to get minuets you would go timeinfo.tm_min, both of which you could use as an integer. It would help if you described exactly what you are trying to accomplish with this.
Re: Getting the system time??
May 25, 2010 03:33AM
ok, all i realy wanted to do was allow the user to set an allarm when useing my app (ok game) Now I have all the info i need. Thanks guys. :)

A further development with this is going to be a customisable calinder. Not quite sure how its going to work just yer. but i'll get it up and running and then i'll post it.
Re: Getting the system time??
May 25, 2010 03:51AM
here is a bit more info on the structure
tm_sec    --  seconds after the minute 0-61 (60 and 61 account for leep seconds not used by the wii)
tm_min    --  minutes after the hour 0-59 (exsplains itself but 15 would be quaterpast for example)
tm_hour   --  hours since midnight 0-23 (dito, 0 is obviously midnight)
tm_mday --  day of the month 1-31 (if you cant figure this one out i'm not telling)
tm_mon   --  months since January 0-11 (pritty simple, 0 is jan 1 is frb ext)
tm_year   --  years since 1900 (this is not the same on all systems so i dont know if this is correct, but just check it and see what happens)
tm_wday  -- days since Sunday 0-6 (0 is sunday just like before)
tm_yday   -- days since January 1 0-365 (day of the year, just in case your intrested probably not of any practical use)
tm_isdst   --  Daylight Saving Time flag (never used it, so i cant realy help with this)
hope this helps with you calinder and whatever else you are useing it for.
Sorry, only registered users may post in this forum.

Click here to login