time_t *”转换为“tm *

sudawei123 2010-04-22 10:32:26
struct tm* NewTime;
time_t LongTime;
time(&LongTime);
NewTime=localtime_s(&LongTime,60);//这行出错
m_tTimeData.Year=NewTime->tm_year+1900;
m_tTimeData.Month=NewTime->tm_mon+1;
m_tTimeData.Day=NewTime->tm_mday;
m_tTimeData.DayofWeek=NewTime->tm_wday;

运行的时候出错,提示
error C2664: “localtime_s”: 不能将参数 1 从“time_t *”转换为“tm *”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换

请问这是哪里的问题啊,怎么修改
...全文
166 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sudawei123 2010-04-22
  • 打赏
  • 举报
回复
好的,谢谢了
lylm 2010-04-22
  • 打赏
  • 举报
回复
不一样的东西,不能转换,给你个MSDN例子看看

// crt_localtime_s.c
/* This program uses _time64 to get the current time
* and then uses _localtime64_s() to convert this time to a structure
* representing the local time. The program converts the result
* from a 24-hour clock to a 12-hour clock and determines the
* proper extension (AM or PM).
*/

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

int main( void )
{
struct tm newtime;
char am_pm[] = "AM";
__time64_t long_time;
char timebuf[26];
errno_t err;

// Get time as 64-bit integer.
_time64( &long_time );
// Convert to local time.
err = _localtime64_s( &newtime, &long_time );
if (err)
{
printf("Invalid argument to _localtime64_s.");
exit(1);
}
if( newtime.tm_hour > 12 ) // Set up extension.
strcpy_s( am_pm, sizeof(am_pm), "PM" );
if( newtime.tm_hour > 12 ) // Convert from 24-hour
newtime.tm_hour -= 12; // to 12-hour clock.
if( newtime.tm_hour == 0 ) // Set hour to 12 if midnight.
newtime.tm_hour = 12;

// Convert to an ASCII representation.
err = asctime_s(timebuf, 26, &newtime);
if (err)
{
printf("Invalid argument to asctime_s.");
exit(1);
}
printf( "%.19s %s\n", timebuf, am_pm );
}

64,691

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧