【整理】Linux下日期判断是否为工作日

原创文章,转载请注明: 转载自勤奋的小青蛙
本文链接地址: 【整理】Linux下日期判断是否为工作日

代码:

#include <ctime>
#include <iostream>

int main()
{
    time_t now;
	struct tm *ts;
	char yearchar[80];
	now = time(NULL);
	ts = localtime(&now);
	//ts->tm_mday--;
	//ts->tm_mday--;
	//ts->tm_mday--;
	std::time_t time_temp = mktime(ts); /* Normalise ts */
	const std::tm * time_out = std::localtime(&time_temp);
	strftime(yearchar, sizeof(yearchar), "%Y%m%d", ts);

    //Sunday == 0, Monday == 1, and so on ...
    std::cout << "yearchar = "<< yearchar << ", Today is this day of the week: " << time_out->tm_wday << "\n";
    std::cout << "(Sunday is 0, Monday is 1, and so on...)\n";

  return 0;
}

结果:

yearchar = 20171030, Today is this day of the week: 1

(Sunday is 0, Monday is 1, and so on...)

如下图:

linux_business_day_check来源于:c++ day of week for given date

原创文章,转载请注明: 转载自勤奋的小青蛙
本文链接地址: 【整理】Linux下日期判断是否为工作日

文章的脚注信息由WordPress的wp-posturl插件自动生成



|2|left
打赏

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: