简体   繁体   English

如何在Visual Studio中获取星期几

[英]how to get the current day of week in visual studio

I declared a variable named date with type DateTime in Visual Studio 2017 but when I try to access DateTime::DayOfWeek , I cannot do so. 我在Visual Studio 2017中用类型DateTime声明了一个名为date的变量,但是当我尝试访问DateTime::DayOfWeek ,却无法这样做。 I was trying to give date that value like this 我试图给date这样的值

    DateTime dayy;
    dayy = DateTime::DayOfWeek;

But I get error 但是我得到了错误

A nonstatic member reference must be relative to a specific object 非静态成员引用必须相对于特定对象

Try to use time.h 尝试使用time.h

#include <time.h>

time_t timeObj = time(nullptr);
tm aTime;
localtime_s(&aTime, &timeObj);
std::cout << aTime.tm_wday;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM