| |||||||
| Commercial message | |
| | |
|
![]() |
| | Thread Tools |
| | #1 (permalink) |
| CDFreaks Resident Join Date: Apr 2002 Location: int main() {
Posts: 1,720
| C++ Time Functions I've been having trouble getting my text based program to display the time correctly. I want it to display in the format Code: Www Mmm dd hh:mm:ss yyyy Code: time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); printf ( "Current date and time are: %s", asctime (timeinfo) ); Code: Current date and time are: Sat May 20 15:21:51 2000 Now I can get it to work using gmtime instead of localtime, but then my day of the week, and month are now numeric. And if the tm_hour+(MST) = a negative number, it doesn't convert it (for example -1 does not become 23). For example: Code:
#define MST (-7)
time_t rawtime;
tm * ptm;
time ( &rawtime );
ptm = gmtime ( &rawtime );
printf ("MST Is: %2d %02d %02d %2d:%02d:%02d %0002d\n", ptm->tm_wday, ptm->tm_mon, tm_hour+MST, ptm->tm_min, ptm->tm_sec, ptm->tm_year+1900); Code: MST Is: 3 09 07 -01:15:13 2005
__________________ I smart, learn fast. The Coolest Page Ever My drives: Benq 1640 BSLB Benq 1625 BBHA (Rebadge HP 640c)(Lightscribe) LG GSA-4163B A104 NEC ND-3520A 1.04 NEC ND-3500AG LD 2.FD Liteon SOHW-812s@832s VS0E Liteon SOHW-1633S BS41 Liteon SOHC 5232K NK0H Yamaha CRW-F1 1.0g And yes these are all in one PC. Hehe. |
| | |
| | #2 (permalink) |
| CD Freaks Expert Join Date: Jan 2004
Posts: 592
| Re: C++ Time Functions If you are running Windows, is your system tray clock set up to use a internet time server? This might cause the internal time to be not what you expect. Windows adjust this for you based on your time zone selection. Just a thought. |
| | |
| | #3 (permalink) |
| CDFreaks Resident Join Date: Apr 2002 Location: int main() {
Posts: 1,720
| Re: C++ Time Functions Actually, it's being compiled for my psp The psp shows the correct time (timezone adjusted) on the main menu or ingame by pressing the home button.I just can't figure out a way to print Wed September and be adjusted for my time zone, it seems I can have 1 or the other.
__________________ I smart, learn fast. The Coolest Page Ever My drives: Benq 1640 BSLB Benq 1625 BBHA (Rebadge HP 640c)(Lightscribe) LG GSA-4163B A104 NEC ND-3520A 1.04 NEC ND-3500AG LD 2.FD Liteon SOHW-812s@832s VS0E Liteon SOHW-1633S BS41 Liteon SOHC 5232K NK0H Yamaha CRW-F1 1.0g And yes these are all in one PC. Hehe. |
| | |
| | #4 (permalink) | |
| New on Forum Join Date: Sep 2005
Posts: 18
| Re: C++ Time Functions Quote:
However I consider that solution rather clunky and awkward so if you are targeting Windows OS only you may consider using native API: Code:
#include <stdio.h>
#include <windows.h>
int main(int argc, char *argv[])
{
SYSTEMTIME st;
LCID lc = LOCALE_SYSTEM_DEFAULT; // or LOCALE_USER_DEFAULT
// or MAKELCID(MAKELANGID(p, s), SORT_DEFAULT)
// where p is primary language identifier
// and s is sublanguage identifier (check MSDN)
LPTSTR date, time;
int date_len, time_len;
date_len = GetDateFormat(lc, DATE_LONGDATE, NULL, NULL, NULL, 0);
time_len = GetTimeFormat(lc, LOCALE_NOUSEROVERRIDE, NULL, NULL, NULL, 0);
date = (LPTSTR)malloc(date_len);
time = (LPTSTR)malloc(time_len);
if ((date == NULL) || (time == NULL)) {
printf("Error allocating string buffers\n");
goto bail_out;
}
GetDateFormat(lc, DATE_LONGDATE, NULL, NULL, date, date_len);
GetTimeFormat(lc, LOCALE_NOUSEROVERRIDE, NULL, NULL, time, time_len);
printf("Current date and time is : %s %s\n", date, time);
bail_out:
free(date); // if date or time is NULL free() just returns
free(time);
return 0;
} | |
| | |
| | #5 (permalink) |
| CDFreaks Resident Join Date: Apr 2002 Location: int main() {
Posts: 1,720
| Re: C++ Time Functions Welcome, and thanks for your input! However, the problem is my target is not Windows, but my psp. Is there a way to do this without including windows.h?? Or rather, is there a header file I can download and include to be able to use _tzset()?
__________________ I smart, learn fast. The Coolest Page Ever My drives: Benq 1640 BSLB Benq 1625 BBHA (Rebadge HP 640c)(Lightscribe) LG GSA-4163B A104 NEC ND-3520A 1.04 NEC ND-3500AG LD 2.FD Liteon SOHW-812s@832s VS0E Liteon SOHW-1633S BS41 Liteon SOHC 5232K NK0H Yamaha CRW-F1 1.0g And yes these are all in one PC. Hehe. |
| | |
| | #7 (permalink) |
| CDFreaks Resident Join Date: Apr 2002 Location: int main() {
Posts: 1,720
| Re: C++ Time Functions Yes, psp=Play Station Portable. I've got my environment set up with cygwin. I then got the psp toolchain from here(scroll to bottom) and installed it. The toolchain and pspsdk are written from the guys at ps2dev.org. It seems to use most of the normal functions of C++ but there are some difference when calling functions (such as using the buttons because of the lack of keyboard etc.) and they usually go something like sceKernelSleepThread() or pspDebugScreenClear() etc. Maybe my question would be better suited towards them.
__________________ I smart, learn fast. The Coolest Page Ever My drives: Benq 1640 BSLB Benq 1625 BBHA (Rebadge HP 640c)(Lightscribe) LG GSA-4163B A104 NEC ND-3520A 1.04 NEC ND-3500AG LD 2.FD Liteon SOHW-812s@832s VS0E Liteon SOHW-1633S BS41 Liteon SOHC 5232K NK0H Yamaha CRW-F1 1.0g And yes these are all in one PC. Hehe. |
| | |
| | #9 (permalink) |
| CDFreaks Resident Join Date: Apr 2002 Location: int main() {
Posts: 1,720
| Re: C++ Time Functions Ok thank you very much for your help.
__________________ I smart, learn fast. The Coolest Page Ever My drives: Benq 1640 BSLB Benq 1625 BBHA (Rebadge HP 640c)(Lightscribe) LG GSA-4163B A104 NEC ND-3520A 1.04 NEC ND-3500AG LD 2.FD Liteon SOHW-812s@832s VS0E Liteon SOHW-1633S BS41 Liteon SOHC 5232K NK0H Yamaha CRW-F1 1.0g And yes these are all in one PC. Hehe. |
| | |
| |
| |
![]() |
| If you can't find where you are looking for, then become a member and get an answer fast! We have thousands of people online every moment of the day to help you! Click here |
| Bookmarks |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Integration functions | bigdude | AnyDVD | 1 | 07-11-2007 14:23 |
| No Remote Functions with VCD's ??? | dexterdoo | General Hardware Forum | 1 | 22-03-2007 11:20 |
| CloneDVD2 no longer functions | winpitt | CloneDVD | 2 | 13-12-2006 07:12 |
| Supported Functions - not DVD-R | Willjt | Firmware | 1 | 01-10-2005 08:59 |