whattime.c

来自「在linux下的聊天软件」· C语言 代码 · 共 54 行

C
54
字号
/*
  whattime.c

  for Free Chat

  by Bill Kendrick, ported to NT by Patrick Stepp
  kendrick@zippy.sonoma.edu, stepp@adelphia.net
  http://zippy.sonoma.edu/kendrick/

  October 10, 1997

  Note when compiled, two warnings will occur in this file , however this is normal and doesn't affect the program.
*/

#include <string.h>
#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include "whattime.h"
#include "defines.h"


long getthetime()
{
        long thetime;
        time_t tp;

        thetime = (long) time(&tp);
        return thetime;
}

void whattime(char * buf)
{
       char newshortdate[25];
       long date, nowtime, starttime;
       static struct tm *cur_time;
	 static struct tm *ptm;
       int x;

	 for (x=0; x<25; x++)
	   newshortdate[x] = '\0';

       nowtime = starttime = getthetime();
       cur_time = localtime((time_t *) &nowtime);

    /* Get the time, then create the struct with time values. */
    time(&cur_time); 
    ptm = localtime(&cur_time);

    /* Display the time. */
     sprintf(newshortdate, "%02d:%02d:%02d", ptm->tm_hour+1, ptm->tm_min, ptm->tm_sec);
     strcpy(buf,newshortdate); 
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?