Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 结构tm的OSx时间/区域设置_C_Macos_Time_Timezone - Fatal编程技术网

C 结构tm的OSx时间/区域设置

C 结构tm的OSx时间/区域设置,c,macos,time,timezone,C,Macos,Time,Timezone,我试图在OSx上创建一个带有本地时区的struct tm #import <time.h> #import <xlocale.h>//This is here because I was trying strptime_l int main(int argc, const char * argv[]) { struct tm start; memset(&start, 0, sizeof(struct tm)); const char *forma

我试图在OSx上创建一个带有本地时区的struct tm

#import <time.h>
#import <xlocale.h>//This is here because I was trying strptime_l

int main(int argc, const char * argv[])
{

  struct tm start;
  memset(&start, 0, sizeof(struct tm));
  const char *formatString = "%m/%d/%Y %R";

  (void) strptime("7/15/2013 16:00", formatString, &start);//Mon Jul 15 @ 4pm EST

  printf("%s\n", start.tm_zone); //prints null

  if (!start.tm_zone) {
     time_t now;
     time(&now);
     printf("%s\n", localtime(&now)->tm_zone);//But I have the right timezone here.
  }

  return 0;
}
#导入
#导入//这是因为我在尝试strtime\l
int main(int argc,const char*argv[]
{
struct-tm启动;
memset(&start,0,sizeof(struct tm));
const char*formatString=“%m/%d/%Y%R”;
(void)strtime(“7/15/2013 16:00”,formatString和start);//美国东部时间7月15日星期一下午4点
printf(“%s\n”,start.tm_zone);//打印空值
如果(!start.tm_区域){
现在是时候了;
时间(现在);
printf(“%s\n”,localtime(&now)->tm_zone);//但是我在这里有正确的时区。
}
返回0;
}
根据以下内容:

函数使用当前区域设置时,strptime 函数可以直接传递区域设置。有关更多信息,请参见xlocale(3)


我的最终目标是能够创建一个NSDate对象,以便最终在iPhone上创建一个日历事件。

为什么不使用NSDateFormatter创建一个NSDate对象?@MartinR我可以。但我仍然想理解这个示例的错误。“如果格式字符串没有包含足够的转换规范来完全指定生成的struct tm,则tm的未指定成员将保持不变。”也许它不知道您是在EST还是在EDT中。可以使用
const char*formatString=“%m/%d/%Y%R%Z”;STRTIME(“美国东部时间7/15/2013 16:00”
。注意:我怀疑您的示例时间是“美国东部时间7月15日星期一下午4点”,而不是美国东部时间。