Get Unix timestamp with C++

后端 未结 7 592
南旧
南旧 2020-12-02 20:00

How do I get a uint unix timestamp in C++? I\'ve googled a bit and it seems that most methods are looking for more convoluted ways to represent time. Can\'t I j

7条回答
  •  自闭症患者
    2020-12-02 20:24

    The most common advice is wrong, you can't just rely on time(). That's used for relative timing: ISO C++ doesn't specify that 1970-01-01T00:00Z is time_t(0)

    What's worse is that you can't easily figure it out, either. Sure, you can find the calendar date of time_t(0) with gmtime, but what are you going to do if that's 2000-01-01T00:00Z ? How many seconds were there between 1970-01-01T00:00Z and 2000-01-01T00:00Z? It's certainly no multiple of 60, due to leap seconds.

提交回复
热议问题