无需使用 Boost,strptime您就可以。
假设此处发布了相同的 _adaptive_parser_ 帮助程序:使用 boost 解析日期时间字符串:使用单位数字小时格式
注:样本取自RFC链接
#include "adaptive_parser.h"
#include <string>
#include <iostream>
int main() {
using namespace mylib::datetime;
adaptive_parser parser;
for (std::string const input : {
"1985-04-12T23:20:50.52Z",
"1996-12-19T16:39:57-08:00",
"1990-12-31T23:59:60Z",
"1990-12-31T15:59:60-08:00",
"1937-01-01T12:00:27.87+00:20",
})
try {
std::cout << "Parsing '" << input << "'\n";
std::cout << " -> epoch " << parser(input).count() << "\n";
} catch(std::exception const& e) {
std::cout << "Exception: " << e.what() << "\n";
}
}
Run Code Online (Sandbox Code Playgroud)
印刷
Parsing '1985-04-12T23:20:50.52Z'
-> epoch 482196050
Parsing '1996-12-19T16:39:57-08:00'
-> epoch 851042397
Parsing '1990-12-31T23:59:60Z'
-> epoch 662688000
Parsing '1990-12-31T15:59:60-08:00'
-> epoch 662688000
Parsing '1937-01-01T12:00:27.87+00:20'
-> epoch -1041335973
Run Code Online (Sandbox Code Playgroud)
当然,您可以限制所需子集可接受的模式数量。
| 归档时间: |
|
| 查看次数: |
4298 次 |
| 最近记录: |