跨平台的方式来获得一天的时间? [英] Cross Platform way to get the time of day?
问题描述
有一个简单的方法来获得一天(17:30,01:20 ...等),将在iOS,OSX,Linux和Windows?
Is there a simple way to get time time of day (17:30, 01:20...etc) that would work on iOS, OSX, Linux and Windows?
如果不是有一个Windows的方式和POSIX的方式还是什么?
If not is there a Windows way and a posix way or something?
感谢
推荐答案
可以检索与时间time_t的现在=时间(NULL);
或时间(安培,现在);
您再平常转换为本地时间结构TM * tm_now =本地时间(安培,现在);
。 A 结构TM
包含字段中的年,月,日,星期,时,分,秒的一天。如果你想产生打印输出,的strftime
支持直接。
You then usually convert to local time with struct tm *tm_now = localtime(&now);
. A struct tm
contains fields for the year, month, day, day of week, hour, minute, and second. If you want to produce printable output, strftime
supports that directly.
这两者都是在C和C ++标准,所以他们可以在最正常的平台。
Both of these are in the C and C++ standards, so they are available on most normal platforms.
这篇关于跨平台的方式来获得一天的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!