mardi 8 octobre 2019

Why does std::put_time(std::gmtime with the %z format give back +0100 for UTC?

I have this little example below that is giving me results that I don't understand.

#include <iostream>
#include <string>
#include <vector>
#include <iomanip>

int main() {
    auto currentTime = std::time(nullptr);
    auto currentTime2 = std::time(nullptr);

    std::stringstream ss;
    std::stringstream ss2;

    ss << std::put_time(std::localtime(&currentTime), "%Y-%m-%dT%H:%M:%S %z %Z");
    ss2 << std::put_time(std::gmtime(&currentTime2), "%Y-%m-%dT%H:%M:%S %z %Z");
    std::cout << " time now local = " << ss.str() << std::endl;
    std::cout << " time now gm    = " << ss2.str() << std::endl;
}

On Windows (VS2017) this gives me:

 time now local = 2019-10-08T16:25:17 +0200 W. Europe Summer Time
 time now gm    = 2019-10-08T14:25:17 +0100 W. Europe Standard Time

On Mac (XCode 10) this gives me:

 time now local = 2019-10-08T16:25:17 +0200 CEST
 time now gm    = 2019-10-08T14:25:17 +0100 UTC

Could someone explain to me why the %z gives +0100 for the UTC outputs instead of +0000? What part of logic am I missing?

Running this on http://ideone.com/IspjpG for example always gives +0000.

Aucun commentaire:

Enregistrer un commentaire