我需要使用Java逐行读取大约5-6 GB的大文本文件.
我该怎么办?
我正在尝试将我认为是UTC字符串的时间信息转换为std::mktime在C++中使用的时间戳.我的问题是,<ctime>/ <time.h>没有转换为UTC的功能; mktime只会将时间戳作为本地时间返回.
所以我需要弄清楚时区偏移量并将其考虑在内,但我找不到与平台无关的方法,不涉及将整个代码移植到boost::date_time.有一些我忽略的简单解决方案吗?
我有一个使用 date.h 库在 C++14 下工作的函数,但我正在将程序转换为使用 C++20,但它不再工作。请问我做错了什么?
我的C++14/date.h代码如下:
#include <date/date.h> // latest, installed via vcpkg
#include <chrono>
auto StringToUnix(const std::string& source) -> std::time_t
{
auto in = std::istringstream(source);
auto tp = date::sys_seconds{};
in >> date::parse("%Y-%m-%d %H:%M:%S", tp);
return std::chrono::system_clock::to_time_t(tp);
}
Run Code Online (Sandbox Code Playgroud)
我转换后的C++20函数如下:
#include <chrono>
auto StringToUnix(const std::string& source) -> std::time_t
{
using namespace std::chrono;
auto in = std::istringstream(source);
auto tp = sys_seconds{};
in >> parse("%Y-%m-%d %H:%M:%S", tp);
return system_clock::to_time_t(tp);
}
Run Code Online (Sandbox Code Playgroud)
我在 VS2019 社区(最新)中收到的错误是:
E0304 no instance of overloaded function "parse" matches the …Run Code Online (Sandbox Code Playgroud) 当尝试编译以下示例时:
\nstd::chrono::sys_time<std::chrono::microseconds> timestamp;\nstd::stringstream ss = foo();\nss >> std::chrono::parse("%Y-%m-%d %T", timestamp);\nRun Code Online (Sandbox Code Playgroud)\n我得到:
\nerror: \xe2\x80\x98parse\xe2\x80\x99 is not a member of \xe2\x80\x98std::chrono\xe2\x80\x99\n 15 | ss >> std::chrono::parse("%Y-%m-%d %T", timestamp);\n | ^~~~~\nRun Code Online (Sandbox Code Playgroud)\n我没想到会这样,因为我正在使用g++我能找到的最新版本。
更多信息:
\n$ g++-11 --version\ng++-11 (Ubuntu 11.1.0-1ubuntu1~18.04.1) 11.1.0\n\n$ g++-11 -v\nUsing built-in specs.\nCOLLECT_GCC=g++-11\nCOLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper\nOFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa\nOFFLOAD_TARGET_DEFAULT=1\nTarget: x86_64-linux-gnu\nConfigured with: (...)\nThread model: posix\nSupported LTO compression algorithms: zlib zstd\ngcc version 11.1.0 (Ubuntu 11.1.0-1ubuntu1~18.04.1) \nRun Code Online (Sandbox Code Playgroud)\n我正在编译:
\ng++-11 -std=c++2a -o test time.cc \nRun Code Online (Sandbox Code Playgroud)\n这只是不支持吗g++-11.1.0?
如何在C++中以下列格式获取日期:
2016-04-26T19:50:48Z
#include <chrono>
#include <ctime>
time_t _tm = time(NULL);
struct tm*curtime = localtime(&_tm);
Run Code Online (Sandbox Code Playgroud)
输出为 asctime(curtime)
目前的输出是: "Thu Apr 28 16:02:41 2016\n"