[英]Get the Local Time in C++ Visual Studio 2015 Community
I have looked all over for ways to get the current time in C++ for a Console Application project, but every method I have found has been rejected by Visual Studio as incorrect or deprecated, even with #define tags to keep the program from deprecating the functions. 我一直在寻找各种方法来获取C ++的控制台应用程序项目的当前时间,但是我发现的每个方法都已被Visual Studio拒绝为不正确或已弃用,即使使用#define标记也可以防止程序弃用该函数。 。 What is the current method to get the current time in a Visual Studio C++ Win32 console application?
在Visual Studio C ++ Win32控制台应用程序中获取当前时间的当前方法是什么?
You may use DateTime::Now
您可以使用
DateTime::Now
using namespace System;
using namespace System::Globalization;
void main()
{
DateTime localDate = DateTime::Now;
array<String^>^ cultureNames = { "en-US", "en-GB", "fr-FR",
"de-DE", "ru-RU" };
for each (String^ cultureName in cultureNames) {
CultureInfo^ culture = gcnew CultureInfo(cultureName);
Console::WriteLine("{0}: {1}", cultureName,
localDate.ToString(culture));
}
}
Feel free to use this free, open-source modern C++ library : 随意使用这个免费的开源现代C ++库 :
#include "tz.h"
#include <iostream>
int
main()
{
std::cout << date::make_zoned(date::current_zone(),
std::chrono::system_clock::now()) << '\n';
}
See the installation section for details on how to install this on Windows. 有关如何在Windows上进行安装的详细信息,请参见安装部分。 It is known to work with VS-2015.
已知可以与VS-2015一起使用。
The library is thread safe and uses no deprecated functionality. 该库是线程安全的,不使用任何不推荐使用的功能。 It also does a lot more things than just getting the current local time.
除了获取当前的本地时间,它还要做很多事情 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.