1 Star 1 Fork 0

yxyc-137/Team collaboration calendar

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
global.cpp 3.84 KB
一键复制 编辑 原始数据 按行查看 历史
#include"global.h"
using namespace std;
unsigned int now_year = get_now_year_month()[0];
unsigned int now_month = get_now_year_month()[1];
unsigned int now_day = get_now_day();
const char * reset = "\033[0m";//重置
const char * f_red = "\033[31m";//红色
const char * f_green = "\033[32m";//绿色
const char * f_black = "\033[30m";//黑色
const char * f_yellow = "\033[33m";//黄色
const char * f_blue = "\033[34m";//蓝色
const char * f_purple = "\033[35m";//紫色
const char * f_qingse = "\033[36m";//青色
const char * f_white = "\033[37m";//白色
const char * b_red = "\033[41m";//红色
const char * b_green = "\033[42m";//绿色
const char * b_black = "\033[40m";//黑色
const char * b_yellow = "\033[43m";//黄色
const char * b_blue = "\033[44m";//蓝色
const char * b_purple = "\033[45m";//紫色
const char * b_qingse = "\033[46m";//青色
const char * b_white = "\033[47m";//白色
// 将 time_point 转换为 int64_t
int64_t time_point_to_int64(const std::chrono::time_point<std::chrono::steady_clock>& tp) {
return std::chrono::duration_cast<std::chrono::nanoseconds>(tp.time_since_epoch()).count();
}
// 将 int64_t 转换为 time_point
std::chrono::time_point<std::chrono::steady_clock> int64_to_time_point(int64_t ns) {
return std::chrono::time_point<std::chrono::steady_clock>(std::chrono::nanoseconds(ns));
}
std::array<unsigned int,2> get_now_year_month()
{
auto now_time = std::time(nullptr);
std::tm now_tm;
localtime_s(&now_tm,&now_time);
unsigned int now_month_number = now_tm.tm_mon + 1;
unsigned int now_year_number = now_tm.tm_year + 1900;
return {now_year_number,now_month_number};
}
//获取当前号数
unsigned int get_now_day()
{
auto now_time = std::time(nullptr);
std::tm now_tm;
localtime_s(&now_tm,&now_time);
unsigned int now_day_number = now_tm.tm_mday;
return now_day_number;
}
bool string_is_space(std::string s)
{
return all_of(s.begin(),s.end(),[](wchar_t ch)->bool{return ch == ' ' || ch == '\t';});
}
//判断string是否全是数字,若是则返回该数字
bool string_is_number(std::string s)
{
return all_of(s.begin(),s.end(),[](wchar_t ch)->bool{return ch == '0' || ch == '1' || ch == '2' || ch == '3' || ch == '4' || ch == '5' || ch == '6' || ch == '6' || ch == '7' || ch == '8' || ch == '9';});
}
unsigned int string_to_unsigned(std::string s)
{
return stoul(s);
}
//返回指定月的一号星期几
unsigned int get_xingqi(unsigned int year,unsigned int month)
{
if(month < 3)
{
month += 12;
year--;
}
unsigned int k = year % 100;
unsigned int j = year / 100;
unsigned int day = (1 + 13 * (month + 1) / 5 + k + k / 4 + 5 * j + j / 4) % 7;
return (day + 5) % 7 + 1;
}
//接受星期几,返回字符串
string get_xingqi(unsigned int xingqi)
{
switch(xingqi % 7)
{
default:
return "";
case 1:
return "一";
case 2:
return "二";
case 3:
return "三";
case 4:
return "四";
case 5:
return "五";
case 6:
return "六";
case 0:
return "日";
}
}
//打印当前时间
void print_now_time()
{
auto now = std::chrono::system_clock::now();
std::time_t now_time = std::chrono::system_clock::to_time_t(now);
std::tm now_tm;
localtime_s(&now_tm,&now_time);
std::cout << std::put_time(&now_tm,"%Y-%m-%d %H:%M");
}
bool isLeapYear(int year)
{
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int daysInMonth(int year,int month)
{
switch(month)
{
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
return 31;
case 4: case 6: case 9: case 11:
return 30;
case 2:
return isLeapYear(year) ? 29 : 28;
default:
return -1;
}
}
array<int,3> nextDay(int year,int month,int day)
{
int days_this_month = daysInMonth(year,month);
if(day < days_this_month)
{
++day;
}
else
{
day = 1;
if(month < 12)
{
++month;
}
else
{
month = 1;
++year;
}
}
return {year,month,day};
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/yxyc-137/Team_collaboration_calendar.git
git@gitee.com:yxyc-137/Team_collaboration_calendar.git
yxyc-137
Team_collaboration_calendar
Team collaboration calendar
master

搜索帮助