加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

什么是localtime函数的有效参数?

发布时间:2020-12-16 10:12:25 所属栏目:百科 来源:网络整理
导读:我这里有一个使用localtime函数的代码.但是对于其输入参数的某些值,代码崩溃(返回空指针).我想知道它的输入允许范围. #include stdio.h#include time.hint main (){ time_t rawtime; struct tm g; struct tm *gp; __int64 tim; tim = 7476811632013133299LL;
我这里有一个使用localtime函数的代码.但是对于其输入参数的某些值,代码崩溃(返回空指针).我想知道它的输入允许范围.

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

int main ()
{
  time_t rawtime;
  struct tm g;
  struct tm *gp;
  __int64 tim;

  tim = 7476811632013133299LL; // I know it's a weird number but valid for time_t
  rawtime = tim / 1000LL;
  gp = localtime(&rawtime);
  printf("Pointer gp = %pn",gp);

  g = *gp; // this crahses because gp = NULL

  return 0;
}

那么可以说关于本地时间函数的允许输入范围呢?

解决方法

从 MSDN page for localtime

Return a pointer to the structure result,or NULL if the date passed
to the function is:

  • Before midnight,January 1,1970.

  • After 03:14:07,January 19,2038,UTC (using _time32 and time32_t).

  • After 23:59:59,December 31,3000,UTC (using _time64 and __time64_t).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读