在 Java 中你可以这样做:
long now = (new Date()).getTime();
我怎样才能用 C++ 做同样的事情呢?
因为 C++0x 太棒了
namespace sc = std::chrono;
auto time = sc::system_clock::now(); // get the current time
auto since_epoch = time.time_since_epoch(); // get the duration since epoch
// I don't know what system_clock returns
// I think it's uint64_t nanoseconds since epoch
// Either way this duration_cast will do the right thing
auto millis = sc::duration_cast<sc::milliseconds>(since_epoch);
long now = millis.count(); // just like java (new Date()).getTime();
这有效 http://ideone.com/MQEbh与海湾合作委员会 4.4+。编译它--std=c++0x
。不知道VS2010是否实现std::chrono
yet.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)