mf_getdate.c
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:2k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2000 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. /* Get date in a printable form: yyyy-mm-dd hh:mm:ss */
  14. #include "mysys_priv.h"
  15. #include <m_string.h>
  16. /*
  17.   If flag & 1 Return date and time
  18.   If flag & 2 Return short date format YYMMDD
  19.   if flag & 4 Return time in HHMMDD format.
  20.   */
  21. void get_date(register my_string to, int flag, time_t date)
  22. {
  23.    reg2 struct tm *start_time;
  24.    time_t skr;
  25. #if defined(HAVE_LOCALTIME_R) && defined(_REENTRANT)
  26.   struct tm tm_tmp;
  27. #endif
  28.    skr=date ? (time_t) date : time((time_t*) 0);
  29. #if defined(HAVE_LOCALTIME_R) && defined(_REENTRANT)
  30.    localtime_r(&skr,&tm_tmp);
  31.    start_time= &tm_tmp;
  32. #else
  33.    start_time=localtime(&skr);
  34. #endif
  35.    if (flag & 2)
  36.      sprintf(to,"%02d%02d%02d",
  37.      start_time->tm_year % 100,
  38.      start_time->tm_mon+1,
  39.      start_time->tm_mday);
  40.    else
  41.      sprintf(to,"%d-%02d-%02d",
  42.      start_time->tm_year+1900,
  43.      start_time->tm_mon+1,
  44.      start_time->tm_mday);
  45.    if (flag & 1)
  46.      sprintf(strend(to)," %2d:%02d:%02d",
  47.      start_time->tm_hour,
  48.      start_time->tm_min,
  49.      start_time->tm_sec);
  50.    else if (flag & 4)
  51.      sprintf(strend(to),"%02d%02d%02d",
  52.      start_time->tm_hour,
  53.      start_time->tm_min,
  54.      start_time->tm_sec);
  55. } /* get_date */