在格式中以C打印时间的最佳方法是2009?08?10 ?18:17:54.811什么?
我有这样的事情:
char *current_day, *current_time;
system("date +%F");
system("date +%T");
Run Code Online (Sandbox Code Playgroud)
它在stdout中打印当前日期和时间,但我想获取此输出或将它们分配给current_day和current_time变量,以便稍后我可以使用这些值进行一些处理.
current_day ==> current day
current_time ==> current time
Run Code Online (Sandbox Code Playgroud)
我现在能想到的唯一解决方案是将输出定向到某个文件,然后读取文件,然后将日期和时间的值分配给current_day和current_time.但我认为这不是一个好方法.还有其他短而优雅的方式吗?