c++ - 如何导入 2 个不同的时区以检查两者是否都是星期一?
问题描述
希望这是有道理的,但我基本上希望程序检查它是否是 2 个不同时区的星期一。如果是,它应该打印一些东西,如果不打印其他东西。像这样的东西:
#include <iostream>
#include <sometimething>
using namespace std;
int a = timezone A;
int b = timezone B;
int main()
{
if (a == mday() || b == mday())
{
cout << "Something1\n";
}
else
{
cout << "Something2\n";
}
return 0;
}
解决方案
你在什么环境下工作?
阅读本页了解本地时间功能。
他们提供了一个很好的例子:
#include <iostream>
#include <iomanip>
#include <ctime>
#include <stdlib.h> // defines putenv in POSIX
int main()
{
std::time_t t = std::time(nullptr);
std::cout << "UTC: " << std::put_time(std::gmtime(&t), "%c %Z") << '\n';
std::cout << "local: " << std::put_time(std::localtime(&t), "%c %Z") << '\n';
// POSIX-specific:
std::string tz = "TZ=Asia/Singapore";
putenv(tz.data());
std::cout << "Singapore: " << std::put_time(std::localtime(&t), "%c %Z") << '\n';
}
哪个输出:
UTC: Fri Sep 15 14:16:29 2017 GMT
local: Fri Sep 15 14:16:29 2017 UTC
Singapore: Fri Sep 15 22:16:29 2017 SGT
您可以定义自己的时区来检索其本地时间。
推荐阅读
- android - Socket.io Android SSL 使用
- python - TypeError: unhashable type: 'dict' with list comprehension
- python - 如何使用 numpy 处理时间敏感数据?
- jwt - JWT 令牌和刷新令牌有什么区别?
- php - 检查 Internet 访问的更好和更简单的方法。PHP 定时任务
- python - 在 Windows 中运行 Flask 看不到环境变量
- firefox-addon-webextensions - 如何侦听 Web 应用程序本身启动的 Web 扩展程序中的 URL 更改?
- vb.net - vb.net 表单不会启动它只是关闭
- php - 将会话变量插入 MySQL
- r - 在 R 中替换矩阵中的 NA