Page 1 of 1

ps2 system time

Posted: Sun May 06, 2007 9:00 am
by JorDy
There seems to be an error with the Hours returned from cdReadClock, my ps2 system clock was around 23:37 when i ran this but cdReadClock returned that my hours was 08 yet everything else was correct. I also got a friend to run this and his time was 18:?? and his returned 20:?? can someone tell me what the problem is?

Posted: Sun May 06, 2007 4:54 pm
by Polo35
Time return by cdreadclock is time in Japan GTM+9.

Take a look in myps2 1.2 source code, there is a libps2time which deal with ps2 clock.

Best regards

Polo

Posted: Sun May 06, 2007 8:30 pm
by JorDy
thanks a lot! i thought there was something strange with the time difference!

*edit* im now getting a funny date, its the 6th of may and its telling me its the 29th

Posted: Wed May 09, 2007 3:31 am
by Polo35
Hey.

Here a simple code i wrote some time ago:

Code: Select all

#define BCD2DEC(bcd)	   (((((bcd)>>4) & 0x0F) * 10) + ((bcd) & 0x0F)) 
#define IS_LEAP_YEAR(Y)  ( ((Y)>0) && !((Y)%4) && ( ((Y)%100) || !((Y)%400) ) )

static char CurClock[ 256 ];

void GetClock ( void ) {

	CdvdClock_t clock;
	int			   nMinute;
	int			   nHour;
	int			   nDay;
	int			   nMonth;
	int			   nYear;
	s32			   nGMTOffset;

	int			   nMonthsDays[] =
 			{	31, 28, 31,	30,	31,	30,	31,	31,	30,	31,	30,	31	};

	cdReadClock( &clock );
	s32 TimeZone = configGetTimezone();
	int DayLightSaving = configIsDaylightSavingEnabled();


	nGMTOffset = TimeZone / 60;
	nMinute		 = BCD2DEC(clock.minute);
	nHour		   = BCD2DEC(clock.hour);		// Hour in Japan (GMT + 9)
	nDay		   = BCD2DEC(clock.day);
	nMonth	   = BCD2DEC(clock.month);
	nYear		   = BCD2DEC(clock.year);
	nYear		   = nYear + 2000;
	nMonth		 = nMonth;
	nDay		   = nDay;
	nHour		   = nHour - 9 + nGMTOffset + DayLightSaving;

	if&#40; nHour < 0 &#41; &#123;
		nHour += 24;
		if&#40; --nDay == 0 &#41; &#123;
			if&#40; --nMonth == 0 &#41; &#123;
				nMonth = 11;
				nYear--;
			&#125; /* end if */
			nDay = nMonthsDays&#91;nMonth&#93;;
			if&#40; nMonth == 2 && IS_LEAP_YEAR&#40;nYear&#41; &#41;
				nDay++;
		&#125; /* end if */
	&#125; /* end if */

	snprintf&#40; CurClock, sizeof&#40; CurClock &#41;, "%02i/%02i/%i  %02i&#58;%02i", nDay, nMonth, nYear, nHour, nMinute &#41;;

&#125; /* end GetClock */
Best regards

Polo

Posted: Wed May 09, 2007 4:32 am
by JorDy
absolutely perfect!! thank you so much