PS-Trainer C - Entwicklung
Bibliotheks-Funktionen: Datum und Zeit lesen
Homepage von PS-Trainer - C-Entwicklung - Datum & Zeit - an PS-Trainer
PS-Trainer PS-Trainer

Date and Time Management  
time Gets the system time.
_ftime , structure _timeb Gets the current time.
_strtime, _wstrtime Copy the time to a buffer.
_strdate, _wstrdate Copy a date to a buffer.


time
Gets the system time.
time_t time( time_t *timer );

Routine Required Header Compatibility
time <time.h> ANSI, Win 95, Win NT

Remarks
The time function returns the number of seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time, according to the system clock. The return value is stored in the location given by timer. This parameter may be NULL, in which case the return value is not stored.

Subject: Time Management Routines
Keywords: See also asctime, _ftime, gmtime, localtime, _utime
Return Value
time returns the time in elapsed seconds. There is no error return.

Parameter
timer Storage location for time

Example
/* TIMES.C illustrates various time and date functions including:
* time _ftime ctime asctime
* localtime gmtime mktime _tzset
* _strtime _strdate strftime
*
* Also the global variable:
* _tzname
*/

#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <string.h>

void main()
{
char tmpbuf[128], ampm[] = "AM";
time_t ltime;
struct _timeb tstruct;
struct tm *today, *gmt, xmas = { 0, 0, 12, 25, 11, 93 };

/* Set time zone from TZ environment variable. If TZ is not set,
* the operating system is queried to obtain the default value
* for the variable.
*/
_tzset();

/* Display operating system-style date and time. */
_strtime( tmpbuf );
printf( "OS time:\t\t\t\t%s\n", tmpbuf );
_strdate( tmpbuf );
printf( "OS date:\t\t\t\t%s\n", tmpbuf );

/* Get UNIX-style time and display as number and string. */
time( &ltime );
printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime );
printf( "UNIX time and date:\t\t\t%s", ctime( &ltime ) );

/* Display UTC. */
gmt = gmtime( &ltime );
printf( "Coordinated universal time:\t\t%s", asctime( gmt ) );

/* Convert to time structure and adjust for PM if necessary. */
today = localtime( &ltime );
if( today->tm_hour > 12 )
{
strcpy( ampm, "PM" );
today->tm_hour -= 12;
}
if( today->tm_hour == 0 ) /* Adjust if midnight hour. */
today->tm_hour = 12;

/* Note how pointer addition is used to skip the first 11
* characters and printf is used to trim off terminating
* characters.
*/
printf( "12-hour time:\t\t\t\t%.8s %s\n",
asctime( today ) + 11, ampm );

/* Print additional time information. */
_ftime( &tstruct );
printf( "Plus milliseconds:\t\t\t%u\n", tstruct.millitm );
printf( "Zone difference in seconds from UTC:\t%u\n", tstruct.timezone );
printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] );
printf( "Daylight savings:\t\t\t%s\n", tstruct.dstflag ? "YES" : "NO" );

/* Make time for noon on Christmas, 1993. */
if( mktime( &xmas ) != (time_t)-1 )
printf( "Christmas\t\t\t\t%s\n", asctime( &xmas ) );

/* Use time structure to build a customized time string. */
today = localtime( &ltime );

/* Use strftime to build a customized time string. */
strftime( tmpbuf, 128,
"Today is %A, day %d of %B in the year %Y.\n", today );
printf( tmpbuf );
}

Output
OS time: 21:51:03
OS date: 05/03/94
Time in seconds since UTC 1/1/70: 768027063
UNIX time and date: Tue May 03 21:51:03 1994
Coordinated universal time: Wed May 04 04:51:03 1994
12-hour time: 09:51:03 PM
Plus milliseconds: 279
Zone difference in seconds from UTC: 480
Time zone name:
Daylight savings: YES
Christmas Sat Dec 25 12:00:00 1993

Today is Tuesday, day 03 of May in the year 1994.


_ftime
Gets the current time.
void _ftime( struct _timeb *timeptr );

Routine Required Header Compatibility
_ftime <sys/types.h> and <sys/timeb.h> Win 95, Win NT

Remarks
The _ftime function gets the current local time and stores it in the structure pointed to by timeptr.
The _timeb structure is defined in SYS\TIMEB.H. It contains four fields:
dstflag Nonzero if daylight savings time is currently in effect for the local time zone. (See _tzset for an explanation of how daylight savings time is determined.)
millitm Fraction of a second in milliseconds.
time Time in seconds since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC).
timezone Difference in minutes, moving westward, between UTC and local time. The value of timezone is set from the value of the global variable _timezone (see _tzset).

Subject: Time Management Routines
Keywords: See also asctime, ctime, gmtime, localtime, time
Return Value
_ftime does not return a value, but fills in the fields of the structure pointed to by timeptr.

Parameter
timeptr Pointer to _timeb structure

Example
/* FTIME.C: This program uses _ftime to obtain the current
* time and then stores this time in timebuffer.
*/

#include <stdio.h>
#include <sys/timeb.h>
#include <time.h>

void main( void )
{
struct _timeb timebuffer;
char *timeline;

_ftime( &timebuffer );
timeline = ctime( & ( timebuffer.time ) );

printf( "The time is %.19s.%hu %s", timeline, timebuffer.millitm, &timeline[20] );
}


Output
The time is Tue Mar 21 15:26:41.341 1995


_strtime, _wstrtime
Copy the time to a buffer.
char *_strtime( char *timestr );
wchar_t *_wstrtime( wchar_t *timestr );


Routine Required Header Compatibility
_strtime <time.h> Win 95, Win NT
_wstrtime <time.h> or <wchar.h> Win 95, Win NT

Remarks
The _strtime function copies the current local time into the buffer pointed to by timestr. The time is formatted as hh:mm:ss where hh is two digits representing the hour in 24-hour notation, mm is two digits representing the minutes past the hour, and ss is two digits representing seconds. For example, the string 18:23:44 represents 23 minutes and 44 seconds past 6 P.M. The buffer must be at least 9 bytes long.
_wstrtime is a wide-character version of _strtime; the argument and return value of _wstrtime are wide-character strings. These functions behave identically otherwise.

Generic-Text Routine Mappings
TCHAR.H _UNICODE & _MBCS _MBCS _UNICODE
Routine Not Defined Defined Defined
_tstrtime _strtime _strtime _wstrtime

Subject: Time Management Routines
Keywords: See also asctime, ctime, gmtime, localtime, mktime, time, _tzset
Return Value
Each of these functions returns a pointer to the resulting character string timestr.

Parameter
timestr Time string

Example
/* STRTIME.C */

#include <time.h>
#include <stdio.h>

void main( void )
{
char dbuffer [9];
char tbuffer [9];
_strdate( dbuffer );
printf( "The current date is %s \n", dbuffer );
_strtime( tbuffer );
printf( "The current time is %s \n", tbuffer );
}


Output
The current date is 03/23/93
The current time is 13:40:40


_strdate, _wstrdate
Copy a date to a buffer.
char *_strdate( char *datestr );
wchar_t *_wstrdate( wchar_t *datestr );


Routine Required Header Compatibility
_strdate <time.h> Win 95, Win NT
_wstrdate <time.h> or <wchar.h> Win 95, Win NT

Remarks
The _strdate function copies a date to the buffer pointed to by datestr, formatted mm/dd/yy, where mm is two digits representing the month, dd is two digits representing the day, and yy is the last two digits of the year.
For example, the string 12/05/99 represents December 5, 1999.
The buffer must be at least 9 bytes long.
_wstrdate is a wide-character version of _strdate; the argument and return value of _wstrdate are wide-character strings. These functions behave identically otherwise.

Generic-Text Routine Mappings
TCHAR.H _UNICODE & _MBCS _MBCS _UNICODE
Routine Not Defined Defined Defined
_tstrdate _strdate _strdate _wstrdate

Subject: Time Management RoutinesTime Management Routines
Keywords: See also asctime, ctime, gmtime, localtime, mktime, time, _tzset
Return Value
Each of these functions returns a pointer to the resulting character string datestr.

Parameter
datestr A pointer to a buffer containing the formatted date string

Example
/* TIMES.C illustrates various time and date functions including:
* time _ftime ctime asctime
* localtime gmtime mktime _tzset
* _strtime _strdate strftime
*
* Also the global variable:
* _tzname
*/

#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <string.h>

void main()
{
char tmpbuf[128], ampm[] = "AM";
time_t ltime;
struct _timeb tstruct;
struct tm *today, *gmt, xmas = { 0, 0, 12, 25, 11, 93 };

/* Set time zone from TZ environment variable. If TZ is not set,
* the operating system is queried to obtain the default value
* for the variable.
*/
_tzset();

/* Display operating system-style date and time. */
_strtime( tmpbuf );
printf( "OS time:\t\t\t\t%s\n", tmpbuf );
_strdate( tmpbuf );
printf( "OS date:\t\t\t\t%s\n", tmpbuf );

/* Get UNIX-style time and display as number and string. */
time( &ltime );
printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime );
printf( "UNIX time and date:\t\t\t%s", ctime( &ltime ) );

/* Display UTC. */
gmt = gmtime( &ltime );
printf( "Coordinated universal time:\t\t%s", asctime( gmt ) );

/* Convert to time structure and adjust for PM if necessary. */
today = localtime( &ltime );
if( today->tm_hour > 12 )
{
strcpy( ampm, "PM" );
today->tm_hour -= 12;
}
if( today->tm_hour == 0 ) /* Adjust if midnight hour. */
today->tm_hour = 12;

/* Note how pointer addition is used to skip the first 11
* characters and printf is used to trim off terminating
* characters.
*/
printf( "12-hour time:\t\t\t\t%.8s %s\n",
asctime( today ) + 11, ampm );

/* Print additional time information. */
_ftime( &tstruct );
printf( "Plus milliseconds:\t\t\t%u\n", tstruct.millitm );
printf( "Zone difference in seconds from UTC:\t%u\n",
tstruct.timezone );
printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] );
printf( "Daylight savings:\t\t\t%s\n",
tstruct.dstflag ? "YES" : "NO" );

/* Make time for noon on Christmas, 1993. */
if( mktime( &xmas ) != (time_t)-1 )
printf( "Christmas\t\t\t\t%s\n", asctime( &xmas ) );

/* Use time structure to build a customized time string. */
today = localtime( &ltime );

/* Use strftime to build a customized time string. */
strftime( tmpbuf, 128,
"Today is %A, day %d of %B in the year %Y.\n", today );
printf( tmpbuf );
}

Output
OS time: 21:51:03
OS date: 05/03/94
Time in seconds since UTC 1/1/70: 768027063
UNIX time and date: Tue May 03 21:51:03 1994
Coordinated universal time: Wed May 04 04:51:03 1994
12-hour time: 09:51:03 PM
Plus milliseconds: 279
Zone difference in seconds from UTC: 480
Time zone name:
Daylight savings: YES
Christmas Sat Dec 25 12:00:00 1993

Today is Tuesday, day 03 of May in the year 1994.


Homepage von PS-Trainer - C-Entwicklung - Datum &Zeit - an PS-Trainer

Aktuelle Daten dieser Seite Letzte Änderung:
  Geocities

 

 

 

Hosted by www.Geocities.ws

1