elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


  Mostrar Mensajes
Páginas: 1 ... 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 [160]
1591  Programación / Programación C/C++ / Re: [C] Como usar time.h en: 6 Marzo 2006, 14:46 pm
Un ejemplo sobre como imprimir la fecha actual mediante las funciones que mencionas y tambien de una forma mas "manual" es (C estandar):
Código:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

#define LONG_CADENA 128

int main(void)
{
   time_t fecha;
   struct tm *temp;
   struct tm fecha_tm;
   char salida[LONG_CADENA];
   
   /* obtener fecha (time_t) */
   if ((fecha = time(NULL)) == (time_t) -1)
      return EXIT_FAILURE;
   
   /* obtener fecha (struct tm) */
   temp = localtime(&fecha);
   memcpy(&fecha_tm, temp, sizeof fecha_tm);
   
   /* imprimir mediante las funciones de la biblioteca time.h */
   printf("%s", ctime(&fecha));
   strftime(salida, LONG_CADENA, "%a %b %d %H:%M:%S %Y\n", &fecha_tm);
   printf("%s", salida);
   
   /* imprimir manualmente */
   printf("        %02d %02d:", fecha_tm.tm_mday, fecha_tm.tm_hour);
   printf("%02d:%02d ", fecha_tm.tm_min, fecha_tm.tm_sec);
   printf("%d\n", fecha_tm.tm_year + 1900);
   
   return EXIT_SUCCESS;
}

Un saludo
Páginas: 1 ... 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 [160]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines