开发者

How to find the day of a Date

开发者 https://www.devze.com 2023-01-01 00:19 出处:网络
I want to find the day of the week of a p开发者_开发知识库articular date in Qt. e.g.: 1/05/2010 is Sunday.

I want to find the day of the week of a p开发者_开发知识库articular date in Qt. e.g.: 1/05/2010 is Sunday.

Is it possible to find the weekday using date?


QDate date;
date.setDate(2010,5,1);
int day = date.dayOfWeek();
QString weekDay = QDate::longDayName(day);

This isn't tested. But hope it will work. Check it out and let know.


int QDate::dayOfWeek () const

Returns the weekday (1 to 7) for this date.

For example,

QDate date;
date.setDate(2010, 5, 1);

switch (date.dayOfWeek()) {
 case 1:
  // Monday
  break;
 // etc...
}


I think you want the QDate class and the dayOfWeek function.

int QDate::dayOfWeek () const

Returns the weekday (1 to 7) for this date.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号