跨平台的方式来获得一天的时间? [英] Cross Platform way to get the time of day?

查看:139
本文介绍了跨平台的方式来获得一天的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个简单的方法来获得一天(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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆