asctime - C time.h

C examples for time.h:asctime

Type

function

From


<ctime>
<time.h>

Description

Convert tm structure to string

Prototype

char* asctime (const struct tm * timeptr);

Parameters

Parameter Description
timeptr Pointer to a tm structure that contains a calendar time broken down into its components.

Return Value

A -string containing the date and time in a human-readable format.

Demo Code


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

int main ()/*from   ww  w .j  av a 2s  . c o  m*/
{
  time_t rawtime;
  struct tm * timeinfo;

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  printf ( "The current date/time is: %s", asctime (timeinfo) );

  return 0;
}

This program displays the local time defined by the system:

Demo Code

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

int main(void)
 {

  struct tm *ptr;
  time_t lt;//w  w  w .ja  va2  s  .c  om

  lt = time(NULL);
  ptr = localtime(&lt);
  printf(asctime(ptr));

  return 0;
 }

Related Tutorials