• <tfoot id='cuhHk'></tfoot>
  • <legend id='cuhHk'><style id='cuhHk'><dir id='cuhHk'><q id='cuhHk'></q></dir></style></legend>

    <small id='cuhHk'></small><noframes id='cuhHk'>

    <i id='cuhHk'><tr id='cuhHk'><dt id='cuhHk'><q id='cuhHk'><span id='cuhHk'><b id='cuhHk'><form id='cuhHk'><ins id='cuhHk'></ins><ul id='cuhHk'></ul><sub id='cuhHk'></sub></form><legend id='cuhHk'></legend><bdo id='cuhHk'><pre id='cuhHk'><center id='cuhHk'></center></pre></bdo></b><th id='cuhHk'></th></span></q></dt></tr></i><div id='cuhHk'><tfoot id='cuhHk'></tfoot><dl id='cuhHk'><fieldset id='cuhHk'></fieldset></dl></div>

          <bdo id='cuhHk'></bdo><ul id='cuhHk'></ul>

        timegm 跨平台

        timegm cross platform(timegm 跨平台)
      1. <tfoot id='zZudp'></tfoot>

      2. <legend id='zZudp'><style id='zZudp'><dir id='zZudp'><q id='zZudp'></q></dir></style></legend>

            <tbody id='zZudp'></tbody>
            <i id='zZudp'><tr id='zZudp'><dt id='zZudp'><q id='zZudp'><span id='zZudp'><b id='zZudp'><form id='zZudp'><ins id='zZudp'></ins><ul id='zZudp'></ul><sub id='zZudp'></sub></form><legend id='zZudp'></legend><bdo id='zZudp'><pre id='zZudp'><center id='zZudp'></center></pre></bdo></b><th id='zZudp'></th></span></q></dt></tr></i><div id='zZudp'><tfoot id='zZudp'></tfoot><dl id='zZudp'><fieldset id='zZudp'></fieldset></dl></div>

            <small id='zZudp'></small><noframes id='zZudp'>

                • <bdo id='zZudp'></bdo><ul id='zZudp'></ul>

                • 本文介绍了timegm 跨平台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用的是 Visual Studio c++ Compiler (2010),但该库具有不同的 ANSI C 和 POSIX 库函数实现.

                  I'm using Visual Studio c++ Compiler ( 2010 ), but the library has different implementation of ANSI C and POSIX libraries function.

                  ANSI C 函数和 Windows CRT 实现有什么区别?例如,tzset()_tzset()setenv()_setenv() 之间有什么区别?似乎以同样的方式做同样的事情......

                  What is the difference between ANSI C function and Windows CRT implementation? For example what is the difference between tzset() and _tzset() or setenv() ans _setenv()? It seems the do the same thing in the same way...

                  我正在使用 msvc (2010),我是否更喜欢 Windows CRT 实现?

                  I'm using msvc ( 2010 ), have I to prefer the Windows CRT Implementation?

                  编辑 1

                  好吧,我想以一种可移植的方式在 time_t 中转换以 UTC 表示的 struct tm,但是没有可移植的方式来做到这一点.我必须为不同平台(Android、Linux、Windows、Windows CE)编写函数.

                  Well I want convert in a portable way a struct tm expressed in UTC in a time_t, but there's no portable way to do that. I've to write the function for different platform (Android, Linux, Windows, Windows CE ).

                  我见过 这个stackoverflow 帖子 使用了setenvgetenvtzset

                  I've seen this stackoverflow post that uses setenv, getenv and tzset

                  编辑 2

                  不幸的是,经过一些测试,我发现 getenv("TZ") 在 Windows 上返回一个空指针.但是为什么将 UTC 时间结构转换为 time_t 如此困难?

                  Unfortunately after some test I've discovered that getenv("TZ") returns a null pointer on windows. But why is so difficult transform a UTC time struct to a time_t?

                  编辑 3

                  在 Boost 中,我在 boost/chrono/io/time_point_io.hpp 中发现了这段代码.希望这对我有帮助.

                  From Boost I discovered this fragment of code in boost/chrono/io/time_point_io.hpp. Hope this helps me.

                  inline int32_t is_leap(int32_t year)
                  {
                    if(year % 400 == 0)
                    return 1;
                    if(year % 100 == 0)
                    return 0;
                    if(year % 4 == 0)
                    return 1;
                    return 0;
                  }
                  inline int32_t days_from_0(int32_t year)
                  {
                    year--;
                    return 365 * year + (year / 400) - (year/100) + (year / 4);
                  }
                  inline int32_t days_from_1970(int32_t year)
                  {
                    static const int days_from_0_to_1970 = days_from_0(1970);
                    return days_from_0(year) - days_from_0_to_1970;
                  }
                  inline int32_t days_from_1jan(int32_t year,int32_t month,int32_t day)
                  {
                    static const int32_t days[2][12] =
                    {
                      { 0,31,59,90,120,151,181,212,243,273,304,334},
                      { 0,31,60,91,121,152,182,213,244,274,305,335}
                    };
                    return days[is_leap(year)][month-1] + day - 1;
                  }
                  
                  inline time_t internal_timegm(std::tm const *t)
                  {
                    int year = t->tm_year + 1900;
                    int month = t->tm_mon;
                    if(month > 11)
                    {
                      year += month/12;
                      month %= 12;
                    }
                    else if(month < 0)
                    {
                      int years_diff = (-month + 11)/12;
                      year -= years_diff;
                      month+=12 * years_diff;
                    }
                    month++;
                    int day = t->tm_mday;
                    int day_of_year = days_from_1jan(year,month,day);
                    int days_since_epoch = days_from_1970(year) + day_of_year;
                  
                    time_t seconds_in_day = 3600 * 24;
                    time_t result = seconds_in_day * days_since_epoch + 3600 * t->tm_hour + 60 * t->tm_min + t->tm_sec;
                  
                    return result;
                  }
                  

                  推荐答案

                  我在 Windows 上使用以下宏:

                  I use the following macro on Windows:

                  #define timegm _mkgmtime
                  

                  正如 _mkgmtime 一样.

                  这篇关于timegm 跨平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to print vector#39;s data(如何打印矢量的数据)
                  Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  MSVC++ warning flags(MSVC++ 警告标志)
                  How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                  stack overflow error in C++ program(C++程序中的堆栈溢出错误)

                  <small id='cPfEE'></small><noframes id='cPfEE'>

                  <legend id='cPfEE'><style id='cPfEE'><dir id='cPfEE'><q id='cPfEE'></q></dir></style></legend>

                  <i id='cPfEE'><tr id='cPfEE'><dt id='cPfEE'><q id='cPfEE'><span id='cPfEE'><b id='cPfEE'><form id='cPfEE'><ins id='cPfEE'></ins><ul id='cPfEE'></ul><sub id='cPfEE'></sub></form><legend id='cPfEE'></legend><bdo id='cPfEE'><pre id='cPfEE'><center id='cPfEE'></center></pre></bdo></b><th id='cPfEE'></th></span></q></dt></tr></i><div id='cPfEE'><tfoot id='cPfEE'></tfoot><dl id='cPfEE'><fieldset id='cPfEE'></fieldset></dl></div>
                          <bdo id='cPfEE'></bdo><ul id='cPfEE'></ul>
                          <tfoot id='cPfEE'></tfoot>

                              <tbody id='cPfEE'></tbody>