The Open Source Swiss Army Knife

/code/c/unix_c/time/
/code/c/unix_c/time/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /code   /c   /unix_c   /time 
Permalink: epoch_timestamp.c
Title: add
article options : please login   |  raw source view  

/* mod_pgsqllog.c version 1.3  under  */
/* /web_servers/apache/programming/c/mod_pgsqllog  */
/*
//  epoch_timestamp()
//
//  Internal function to convert a integer timestamp value (epoch) to readable timestamp.
//  Format used is yy/mm/dd hh/mm/ss UTC offset, which may need to be
//  modified for specific PostgreSQL setups. Returns timestamp string.
//
//  timer - epoch integer value to convert
//
//  Contributed by Brian Holman (me@brianholman.com)
*/

const char *
epoch_timestamp (time_t timer)
{
  struct tm *tblock;
  static char tmstr[MAX_TIMESTAMP_LEN];

#ifdef _TRACE_C_CALLS
  fprintf (stderr,
           "%s DEBUG: epoch_timestamp() (file: %s, line: %i)\n",
           MODULE_NAME, __FILE__, __LINE__);
#endif

  if ((tblock = localtime (&timer)) == NULL)
  {
    fprintf (stderr,
             "%s ERROR: Failed to convert value %i to tm struct: localtime()\n",
             timer);
    return ("NULL");
  }

  if (strftime (tmstr, MAX_TIMESTAMP_LEN, "%G-%m-%d %H:%M:%S %Z", tblock)
      == 0)
  {
    fprintf (stderr,
             "%s ERROR: Failed to convert value %i into timestamp: strftime()\n",
             timer);
    return ("NULL");
  }

  return (tmstr);
}



Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top