|
 |
|
 |
07-02-2005, 06:29 AM
|
#1 (permalink)
|
|
Registered User
Join Date: Jul 2005
Posts: 4
|
help wit some codes pls
i need to put the time and date into some varieble pls help
in this order pls giv some sample or show me how its done
time variebles
HHMM <==this order
date variebles
DDMMYY<==this order
|
|
|
07-02-2005, 04:27 PM
|
#2 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,712
|
look at ctime(), localtime(), gmtime()
|
|
|
07-02-2005, 08:13 PM
|
#3 (permalink)
|
|
Registered User
Join Date: Jul 2005
Posts: 4
|
u mean
cout <<ctime();
?
coz if so i tryed taht and it dosnt work >.<
|
|
|
07-02-2005, 11:28 PM
|
#4 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,712
|
I'm too hung over, to even explain, so here is a code example.
Code:
#include <stdio.h>
#include <time.h>
int main()
{
struct tm *tm_set;
time_t tim, t;
tim = time(&t);
tm_set = localtime(&tim);
printf("HHMM: %.2d%.2d\n", tm_set->tm_hour, tm_set->tm_min);
printf("DDMMYY: %.2d%.2d%.2d\n", tm_set->tm_mday, tm_set->tm_mon,
(tm_set->tm_year < 100)? tm_set->tm_year: (tm_set->tm_year -100));
return 0;
}
|
|
|
07-03-2005, 06:16 AM
|
#5 (permalink)
|
|
Registered User
Join Date: Jul 2005
Posts: 4
|
wow taht really helps cause it really works thx but it would be even better if they can be stored in variebles cause i need to store them in an array >.<
|
|
|
07-03-2005, 07:43 AM
|
#6 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,712
|
From the description:
Quote:
Broken-down time is stored in the structure tm which is defined in <time.h> as follows:
Code:
struct tm {
int tm_sec; /* seconds */
int tm_min; /* minutes */
int tm_hour; /* hours */
int tm_mday; /* day of the month */
int tm_mon; /* month */
int tm_year; /* year */
int tm_wday; /* day of the week */
int tm_yday; /* day in the year */
int tm_isdst; /* daylight saving time */
};
|
As you see, the variables are of type int, which means you can store them as int's in yoru array, or if you want to have it in the printet format like HHMM and DDMMYY then you can store them as strings, by gathering the int's into a string and store that in your array.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 10:47 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|