Time t

Time t

El tipo de dato time_t es un tipo de dato de la biblioteca ISO-C definido para el almacenamiento de valores de tiempo del sistema. Estos valores se devuelven desde la función time() de la biblioteca estándar. Este tipo es un typedef definido en la cabecera <time.h> . ISO-C define time_t como un tipo aritmético, pero no especifica ningun rango, resolución, o codificación en particular de la misma. Tampoco especifica los significados de las operaciones aritméticas aplicadas a los valores de tiempo.

Contenido

Implementación

Unix y los sistemas compatibles con POSIX, implementan time_t como un entero o real de coma flotante.[1] (generalmente entero de 32 o 64 bits), que representa el número de segundos desde el inicio del tiempo Unix: la medianoche del 1 de enero de 1970 UTC (sin contar los segundos intercalares). Algunos sistemas manejan correctamente los valores negativos, mientras que otros no lo hacen. Los sistemas que utilizan un tipo time_t entero de 32 bits son susceptibles a los problemas del año 2038.[2]

Además de la función time(), ISO-C también especifica otras funciones y tipos de conversión de sistema de valores de tiempo time_t en los tiempos del calendario y viceversa.

Ejemplo

El siguiente código en C devuelve la hora actual, le da formato de cadena, y lo escribe en la salida estándar.

#include <stdio.h>
#include <time.h>
 
/*
 * El resultado debe ser algo así como
 * Fri 2008-08-22 15:21:59 WAST
 */
 
int main(void)
{
    time_t     now;
    struct tm *ts;
    char       buf[80];
 
    /* Obtener la hora actual */
    now = time(0);
 
    /* Formatear e imprimir el tiempo, "ddd yyyy-mm-dd hh:mm:ss zzz" */
    ts = localtime(&now);
    strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", ts);
    printf("%s\n", buf);
 
    return 0;
}

La conversión a la hora civil

Usando GNU date, un valor dado time_t se puede convertir en su equivalente en la fecha del calendario:

$ date -ud@1234567890
Fri Feb 13 23:31:30 UTC 2009

Del mismo modo, usando BSD date:

$ date -ur 1234567890
Fri Feb 13 23:31:30 UTC 2009

Véase también

Referencias

  1. ↑ The Open Group Base Specifications Issue 7 sys/types.h. Retrieved on 2009-02-13.
  2. ↑ The Year 2038 problem, Roger M. Wilcox. Retrieved on 2011-03-11.



Wikimedia foundation. 2010.

Игры ⚽ Поможем написать реферат

Mira otros diccionarios:

  • Time — Time, n.; pl. {Times}. [OE. time, AS. t[=i]ma, akin to t[=i]d time, and to Icel. t[=i]mi, Dan. time an hour, Sw. timme. [root]58. See {Tide}, n.] 1. Duration, considered independently of any system of measurement or any employment of terms which… …   The Collaborative International Dictionary of English

  • Time's Up! — is a grassroots environmental group that seeks to promote a more sustainable, less toxic New York City. For 20 years, it has been committed to improving the environment by empowering individuals to become active in their community. In New York… …   Wikipedia

  • Time UK — is a computer retailer set up by the people behind the failed Time Computer Systems.The company is based within the main factory offices at Time Technology Park in Simonstone, near Burnley in Lancashire. The company specializes in providing… …   Wikipedia

  • Time — (t[imac]m), v. t. [imp. & p. p. {Timed} (t[imac]md); p. pr. & vb. n. {Timing}.] 1. To appoint the time for; to bring, begin, or perform at the proper season or time; as, he timed his appearance rightly. [1913 Webster] There is no greater wisdom… …   The Collaborative International Dictionary of English

  • Time — Time, v. i. 1. To keep or beat time; to proceed or move in time. [1913 Webster] With oar strokes timing to their song. Whittier. [1913 Webster] 2. To pass time; to delay. [Obs.] [1913 Webster] …   The Collaborative International Dictionary of English

  • Time U.K — was an English rock band in the early 1980s. After the split of The Jam in 1982, Drummer Rick Buckler received numerous demo tapes from musicians interested in forming a new band with him. One of these stood out. It was from former Masterswitch… …   Wikipedia

  • Time FM — could meanany of the following radio stations operated by the Sunrise Radio Group:* Time 106.6 * Time 106.8 * Time 107.3 * Time 107.5 …   Wikipedia

  • Time's Up — may refer to:Music* Time s Up (Living Colour album), an album by the band Living Colour. * Time s Up (K Solo album), an album by the American rapper K Solo. * Time s Up (Thee Majesty album), an album by Thee Majesty released in 1999.Television* …   Wikipedia

  • Time — This article is about the measurement. For the magazine, see Time (magazine). For other uses, see Time (disambiguation). The flow of sand in an hourglass can be used to keep track of elapsed time. It also concretely represents the present as… …   Wikipedia

  • time — See: ABOUT TIME, AGAINST TIME, AT A TIME, AT ONE TIME, AT THE SAME TIME, AT TIMES, BEHIND THE TIMES, BEHIND TIME, BIDE ONE S TIME, BIG TIME, EVERY TIME ONE TURNS AROUND, FOR THE TIME BEING, FROM TIME TO TIME, GIVE A HARD TIME, HAVE A TIME, HIGH… …   Dictionary of American idioms

  • time — See: ABOUT TIME, AGAINST TIME, AT A TIME, AT ONE TIME, AT THE SAME TIME, AT TIMES, BEHIND THE TIMES, BEHIND TIME, BIDE ONE S TIME, BIG TIME, EVERY TIME ONE TURNS AROUND, FOR THE TIME BEING, FROM TIME TO TIME, GIVE A HARD TIME, HAVE A TIME, HIGH… …   Dictionary of American idioms

Compartir el artículo y extractos

Link directo
… Do a right-click on the link above
and select “Copy Link”