Jump to content
Fórum Script Brasil
  • 0

Pegar tempo


Marcos Felipe

Question

1 answer to this question

Recommended Posts

  • 0

Olá,

Segue um exemplo que funcional em qualquer sistema operacional.

Exceto pelo system("pause") no final.

Abs


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

void main(void)
{
int dia, mes, ano;
int hora, min, sec;
struct tm *local;
time_t t;
t= time(NULL);
local=localtime(&t);

dia=local->tm_mday;
mes=local->tm_mon+1;
ano=local->tm_year+1900;
printf("Data do Sistema: %d/%d/%d\n",dia,mes,ano);

hora = local->tm_hour;
min = local->tm_min;
sec = local->tm_sec;
printf("Hora do Sistema: %d:%d:%d\n",hora,min,sec);
system("pause");
}
[/codebox]

// so pra você ter ideia, o conteudo da estrutura tm é esse:

#if 0

struct tm {

int tm_sec; /* Segundos, 0-59*/

int tm_min; /* Minutos, 0-59*/

int tm_hour; /*Horas 0-23 */

int tm_mday; /*dia do mês, 1-31 */

int tm_mon; /* mês a partir de janeiro, 0-11 */

int tm_year; /* anos a partir de 1900 */

int tm_wday; /* dias a partir de domingo, 0-6 */

int tm_yday; /* dias a partir de 1 de janeiro 1-365 */

int tm_isdst; /* Indicador de horário de verão */

#endif

Edited by CPP
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652.1k
×
×
  • Create New...