如何从字符串中获取UTC偏移量
How to get UTC offset from string
我得到字符串像2015-04-29 15:36:16.5761891 +03:00
。我可以使用std::get_time
轻松地提取日期。
std::tm time;
std::string stringTime = "2015-04-29 15:36:16.5761891 +03:00";
std::istringstream stringStream(stringTime);
stringStream >> std::get_time(&time, "%Y-%m-%d %H:%M:%S");
cout << time.tm_year << endl;
cout << time.tm_mon << endl;
cout << time.tm_mday << endl;
cout << time.tm_hour << endl;
cout << time.tm_min << endl;
cout << time.tm_sec << endl;
这对我来说很好。现在我如何从这个字符串中提取UTC偏移量?
你可以继续这样读:
#include <ctime>
#include <string>
#include <sstream>
#include <iomanip>
#include <iostream>
int main()
{
std::tm time;
std::string stringTime = "2015-04-29 15:36:16.5761891 +03:00";
std::istringstream stringStream(stringTime);
std::string decimals;
std::string offset;
stringStream >> std::get_time(&time, "%Y-%m-%d %H:%M:%S") >> decimals >> offset;
std::cout << time.tm_year << 'n';
std::cout << time.tm_mon << 'n';
std::cout << time.tm_mday << 'n';
std::cout << time.tm_hour << 'n';
std::cout << time.tm_min << 'n';
std::cout << time.tm_sec << 'n';
std::cout << decimals << 'n';
std::cout << offset << 'n';
}
输出:115
3
29
15
36
16
.5761891
+03:00
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 使用指针从C++中的数组中获取最大值
- 如何获取std::result_of函数的返回类型
- 如何在openssl-ecc中获取十六进制格式的私钥
- 使用Unreal C++获取VR耳机的世界位置/方向
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 从C字符串中获取奇怪的字符串长度
- 为什么我的for循环不能正确获取argv
- 如何使用闰秒以微秒为单位获取 UTC 时间
- 如何在C++中以毫秒为单位获取今天的 UTC 午夜时间?
- 有没有办法在 C++ 中获取 uint64_t 日期的 UTC 纳秒
- 如何获取UTC时间
- 如何使用c++在linux中获取utc偏移量
- C++提升以 UTC 格式获取 unix 时间戳
- 如何获取从epoch到午夜的UTC秒数
- 获取当前时间作为W3C UTC时间字符串
- 在Mac(C++)上获取系统时区的UTC偏移量
- 如何从字符串中获取UTC偏移量