简体   繁体   English

在C ++ Visual Studio 2015社区中获取本地时间

[英]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));
   }
}

For more information, have a look into MSDN 有关更多信息,请查看MSDN。

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.

相关问题 Visual Studio Community 2015 安装 (Visual C++) - Visual Studio Community 2015 Installation (Visual C++) Visual Studio 2015社区C ++构建失败:任务已取消 - Visual Studio 2015 Community C++ Build Failure: A task was cancelled 部署应用程序,C ++,Visual Studio 2015社区版本 - Deploy app, C++, Visual Studio 2015 community version 如何在 Visual Studio Community 2015 上打开输入文件、C++? - How to open input file, C++ on visual studio community 2015? 使用Visual Studio 2015社区版在C ++中#include excel错误 - #include excel error in C++ with Visual Studio 2015, Community edition Visual Studio 2015 社区 - “Visual C++ 项目系统包”错误 - Visual Studio 2015 Community - 'Visual C++ Project System Package' error 编辑并继续不起作用(C ++,Visual Studio Community 2015) - Edit and Continue doesn't work (C++, Visual Studio Community 2015) 对于Visual Studio Community 2015,我可以使用C ++的代码覆盖功能吗? - For Visual Studio Community 2015 can I use code coverage functionality for C++? C ++正则表达式Visual Studio社区2015 <regex> 出乎意料的结果 - C++ regex Visual Studio Community 2015 <regex> gives unexpected results 无法在Visual Studio 2015社区RTM中创建/打开C ++项目 - Unable to create/open C++ project in Visual Studio 2015 Community RTM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM