RAD Studio
ContentsIndex
PreviousUpNext
asctime

Header File 

time.h  

Category 

Time and Date Routines 

Prototype 

char *asctime(const struct tm *tblock); 

wchar_t *_wasctime(const struct tm *tblock); 

Description 

asctime converts date and time to ASCII. 

_wasctime converts date and time to a wchar_t string. 

asctime and _wasctime convert a time stored as a structure to a 26 (wide) character string in the following form: 

Mon Nov 21 11:31:54 1983\n\0 

All the fields have a constant width. The output string day-of-the-week and month correspond to the following: 

tm parameterValid value rangeOutput 

tm.mon (month)0-110=Jan, 1=Feb, and so on 

tm.day (day-of-the-week)0-60=Sun, 1=Mon, and so on 

Return Value 

asctime and _wasctime return a pointer to the (wide) character string containing the date and time. This string is a static which is overwritten with each call. asctime converts a time stored as a structure in *tblock to a 26-character string of the same form as the ctime string: 

Sun Sep 16 01:03:52 1973\n\0 

Example  

#include <string.h>
#include <time.h>
#include <stdio.h>
int main(void)
{
  struct tm t;
  char str[80];
  /* sample loading of tm structure  */
  t.tm_sec    = 1;  /* Seconds */
  t.tm_min    = 30; /* Minutes */
  t.tm_hour   = 9;  /* Hour */
  t.tm_mday   = 22; /* Day of the Month  */
  t.tm_mon    = 11; /* Month */
  t.tm_year   = 56; /* Year - does not include century */
  t.tm_wday   = 4;  /* Day of the week  */
  t.tm_yday   = 0;  /* Does not show in asctime */
  t.tm_isdst  = 0;  /* Is Daylight SavTime; does not show in asctime */
  /* converts structure to null terminated string */
  strcpy(str, asctime(&t));
  printf("%s\n", str);
  return 0;
}

Portability

 
POSIX 
Win32 
ANSI C 
ANSI C++ 
asctime 
_wasctime 
 
 
 
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!