Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在c++;如何找到最长系统日期?_C++_Date_Time - Fatal编程技术网

C++ 在c++;如何找到最长系统日期?

C++ 在c++;如何找到最长系统日期?,c++,date,time,C++,Date,Time,我正在尝试在cpp中查找允许的最大系统日期,但找不到执行该操作的函数 有人能帮我吗?这取决于操作系统,我们在这里使用的是windows还是与POSIX兼容的软件?这取决于操作系统,我们在这里使用的是windows还是与POSIX兼容的软件?使用函数。将值从0传递到numeric\u limits::max()。对于不可接受的值,此函数将返回空指针。您可以使用二进制搜索算法更快地找到合适的值:O(log2n),其中N=数值限制::max() 下面的示例使用boost库,但它仍然与平台无关。如果需要

我正在尝试在cpp中查找允许的最大系统日期,但找不到执行该操作的函数


有人能帮我吗?

这取决于操作系统,我们在这里使用的是windows还是与POSIX兼容的软件?

这取决于操作系统,我们在这里使用的是windows还是与POSIX兼容的软件?

使用函数。将值从
0
传递到
numeric\u limits::max()
。对于不可接受的值,此函数将返回空指针。您可以使用二进制搜索算法更快地找到合适的值:O(log2n),其中N=
数值限制::max()

下面的示例使用boost库,但它仍然与平台无关。如果需要,您可以在不使用STL或boost的情况下实现相同的功能

#include <iostream>
#include <time.h>
#include <limits>
#include <algorithm>
#include <boost/iterator/counting_iterator.hpp>

using namespace std;
using namespace boost;

bool less_time( time_t val1, time_t val2 )
{
    tm* v1 = localtime( &val1 );
    tm* v2 = localtime( &val2 );
    if ( v1 && v2 ) return false;
    if ( !v1 && !v2 ) return false;
    if ( v1 && !v2) return true;
    return false;
};

int main() {
    counting_iterator<time_t> x = upper_bound( counting_iterator<time_t>(0), counting_iterator<time_t>(numeric_limits<time_t>::max()), 0, less_time );
    time_t xx = *x;
    --xx; // upper_bound gives first invalid value so we use previous one
    cout << "Max allowed time is: " << ctime(&xx) << endl;

    return 0;
}
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
使用名称空间boost;
bool更少的时间(时间值1,时间值2)
{
tm*v1=本地时间(&val1);
tm*v2=本地时间(&val2);
如果(v1&&v2)返回false;
如果(!v1&&!v2)返回false;
如果(v1&&!v2)返回true;
返回false;
};
int main(){
计数迭代器x=上界(计数迭代器(0),计数迭代器(数值极限::max()),0,更少的时间);
时间_txx=*x;
--xx;//上界给出了第一个无效值,所以我们使用前一个值
cout使用函数。将值从
0
传递到
数值限制::max()
。对于不可接受的值,此函数将返回空指针。您可以使用二进制搜索算法更快地找到合适的值:O(log2 N),其中N=
数值限制::max()

下面的示例使用boost库,但它仍然与平台无关。如果需要,您可以在不使用STL或boost的情况下实现相同的功能

#include <iostream>
#include <time.h>
#include <limits>
#include <algorithm>
#include <boost/iterator/counting_iterator.hpp>

using namespace std;
using namespace boost;

bool less_time( time_t val1, time_t val2 )
{
    tm* v1 = localtime( &val1 );
    tm* v2 = localtime( &val2 );
    if ( v1 && v2 ) return false;
    if ( !v1 && !v2 ) return false;
    if ( v1 && !v2) return true;
    return false;
};

int main() {
    counting_iterator<time_t> x = upper_bound( counting_iterator<time_t>(0), counting_iterator<time_t>(numeric_limits<time_t>::max()), 0, less_time );
    time_t xx = *x;
    --xx; // upper_bound gives first invalid value so we use previous one
    cout << "Max allowed time is: " << ctime(&xx) << endl;

    return 0;
}
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
使用名称空间boost;
bool更少的时间(时间值1,时间值2)
{
tm*v1=本地时间(&val1);
tm*v2=本地时间(&val2);
如果(v1&&v2)返回false;
如果(!v1&&!v2)返回false;
如果(v1&&!v2)返回true;
返回false;
};
int main(){
计数迭代器x=上界(计数迭代器(0),计数迭代器(数值极限::max()),0,更少的时间);
时间_txx=*x;
--xx;//上界给出了第一个无效值,所以我们使用前一个值

可能会出错…我希望它尽可能标准化…呃…我希望它尽可能标准化…我希望它尽可能标准化windows存储日期和世界其他地方的方式有一个根本性的区别。这是只有操作系统文档才能回答的问题之一。请看,让我们说这是为了符合POSIX标准的系统我希望它尽可能标准化windows存储日期和世界其他地方的方式有根本区别。这是只有操作系统文档才能回答的问题之一。请看,假设这是符合POSIX标准的系统