如何将当前系统时间分配给String ^变量?

时间:2015-10-03 00:44:28

标签: visual-studio visual-c++ visual-studio-2013 c++-cli visual-c++-2013

如何在按钮点击事件中获取当前系统时间,并以(可能)指定的格式(例如:YYYY-MM-DD-HH-MM-SS)将其分配给- (IBAction)sendPressed { if([youtubeurl.text isEqualToString:@""]) { //if it doesnt have value NSLog(@"no youtube clip"); youtubelink = @""; } else{ //if youtube url has been entered NSLog(@"youtube clip found"); completeurl = youtubeurl.text; youtubelink = [completeurl substringFromIndex:16]; } } 变量?

我正在使用Visual Studio 2013。

1 个答案:

答案 0 :(得分:0)

您可以将time功能与localtime功能结合使用。

示例代码:

//#include <time.h>
time_t rawtime;
struct tm * timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
//The years are since 1900 according the documentation, so add 1900 to the actual year result.
printf("Date: %d/%d/%d Time: %d:%d:%d",timeinfo->tm_year + 1900, timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);