August 4th Tuesday

作者反思了现实社会中金钱的重要性,并决定暂时放下技术追求,转而寻求更实际的赚钱之道。尽管如此,在找到真正的致富途径之前,作者仍将继续学习技术,当前正在学习Visual C++。

     Usually woman says that mony is not important for her.  However, in realty man usually have to gain more and more money for his wife or his sweet heart.

 

   Now, I understood that the main task in the future is to gain money more and more, and put the technique learnt aside.  In China, an averge technician can not become a  richer.

 

  No money, no free!  That is a truth at least in China.  If you suspected of that,  you can try to defy it.  I will bless for you.

 

  OK!  Before I get a plan to become a richer, I have to go on learning technique.  I am learning Visual C++.  Maybe, I will live on that in future years.   Although to be a richer is a dream, a goal, I must set off from realty.  Nobody can live on air.  If all right, Visual C++ will be the last that I learn.

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> // 定义每月的最大天数 int month_days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // 判断是否为闰年 int is_leap_year(int year) { return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); } // 打印某个月的日历 void print_month_calendar(int year, int month, int start_day_of_week) { printf("\n %-15s\n", get_month_name(month)); printf("Su Mo Tu We Th Fr Sa\n"); int days_in_month = month_days[month - 1]; if (is_leap_year(year) && month == 2) { days_in_month++; } int day_counter = 1; for (int i = 0; i < start_day_of_week; i++) { printf(" "); } for (int i = start_day_of_week; i < 7; i++, day_counter++) { printf("%2d ", day_counter); } while (day_counter <= days_in_month) { printf("\n"); for (int i = 0; i < 7 && day_counter <= days_in_month; i++, day_counter++) { printf("%2d ", day_counter); } } printf("\n"); } // 获得月份名称 const char* get_month_name(int month) { const char *months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; return months[month - 1]; } // 计算给定日期距离今天的天数 long calculate_days_between_dates(struct tm date1, struct tm date2) { time_t t1 = mktime(&date1), t2 = mktime(&date2); long diff_seconds = difftime(t2, t1); return abs(diff_seconds / (60 * 60 * 24)); } // 主程序入口 int main() { time_t now = time(NULL); struct tm today = *localtime(&now); // 功能1:打印当前年历并标注今天 int current_year = today.tm_year + 1900; printf("Year Calendar of %d:\n", current_year); int first_day_of_year = ((current_year - 1) * 365 + (current_year - 1) / 4 - (current_year - 1) / 100 + (current_year - 1) / 400) % 7; for (int m = 1; m <= 12; m++) { int days_before_this_month = 0; for (int k = 1; k < m; k++) { days_before_this_month += month_days[k - 1]; } if (is_leap_year(current_year) && m >= 3) { days_before_this_month++; } int start_day_of_week = (first_day_of_year + days_before_this_month) % 7; print_month_calendar(current_year, m, start_day_of_week); } // 标记今天的日期 printf("Today's Date (%d-%02d-%02d):\n", current_year, today.tm_mon + 1, today.tm_mday); // 功能2:输入一个年份(1940-2040),输出该年的日历 int input_year; printf("Enter a year between 1940 and 2040 to display its calendar: "); scanf("%d", &input_year); if (input_year >= 1940 && input_year <= 2040) { printf("Calendar of Year %d:\n", input_year); int first_day_input_year = ((input_year - 1) * 365 + (input_year - 1) / 4 - (input_year - 1) / 100 + (input_year - 1) / 400) % 7; for (int m = 1; m <= 12; m++) { int days_before_this_month = 0; for (int k = 1; k < m; k++) { days_before_this_month += month_days[k - 1]; } if (is_leap_year(input_year) && m >= 3) { days_before_this_month++; } int start_day_of_week = (first_day_input_year + days_before_this_month) % 7; print_month_calendar(input_year, m, start_day_of_week); } } else { printf("Invalid year entered.\n"); } // 功能3:输入年月,输出对应月份的日历 int input_month; printf("Enter a year and month separated by space to display the corresponding month's calendar: "); scanf("%d%d", &input_year, &input_month); if (input_year >= 1940 && input_year <= 2040 && input_month >= 1 && input_month <= 12) { int first_day_input_year = ((input_year - 1) * 365 + (input_year - 1) / 4 - (input_year - 1) / 100 + (input_year - 1) / 400) % 7; int days_before_this_month = 0; for (int k = 1; k < input_month; k++) { days_before_this_month += month_days[k - 1]; } if (is_leap_year(input_year) && input_month >= 3) { days_before_this_month++; } int start_day_of_week = (first_day_input_year + days_before_this_month) % 7; print_month_calendar(input_year, input_month, start_day_of_week); } else { printf("Invalid input.\n"); } // 功能4:输入年月日,计算距今天有多少天、是星期几以及是否为公历节日 int input_day; printf("Enter a specific date as 'YYYY MM DD' to compute details about it: "); scanf("%d%d%d", &input_year, &input_month, &input_day); struct tm target_date = {0}; target_date.tm_year = input_year - 1900; target_date.tm_mon = input_month - 1; target_date.tm_mday = input_day; long days_diff = calculate_days_between_dates(target_date, today); int weekday_target = (today.tm_wday + days_diff) % 7; const char *weekdays[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; printf("The specified date is %ld days away from today.\n", days_diff); printf("It falls on a %s.\n", weekdays[weekday_target]); // 假设仅考虑元旦作为示例公历节日
05-27
/* * fn CMM_RET oal_sys_setTZ(TIME_OBJ *pNewObj, const struct tm *pDstStart, const struct tm *pDstEnd, const char *pTimeZone) * brief Set system timezone environment variable * * param[in] pNewObj - The time obj. * param[in] pDstStart - DaylightSavings start time. * param[in] pDstend - DaylightSavings end time. * param[in] pTimeZone - The local time zone. * * return CMM_RET */ CMM_RET oal_sys_setTZ(DEV2_TIME_OBJ *pNewObj, const struct tm *pDstStart, const struct tm *pDstEnd, const char *pTimeZone) { struct timeval tv; struct timeval *setTv = NULL; struct timezone tz; int tzHour = 0, tzMin = 0; #if (defined(__GLIBC__) && !defined(__UCLIBC__)) const char* mon_names[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; const char* week_counts[][2] = { {"",">=1"}, /* 1st*/ {"",">=8"}, /* 2nd */ {"",">=15"}, /* 3rd */ {"",">=22"}, /* 4th */ {"last",""} /* last */ }; const char* wday_names[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; int startWeekCount = 0, endWeekCount = 0; char tzInfo[BUFLEN_512] = {0}; char *pTmp = tzInfo; FILE *fp = NULL; if (pNewObj->daylightSavingsUsed) { /* set the week count as the UI wants */ startWeekCount = pNewObj->X_TP_DaylightSavingsStartWeekCount; endWeekCount = pNewObj->X_TP_DaylightSavingsEndWeekCount; pTmp += sprintf(pTmp, "Rule MYR minimum maximum - %s %s%s%s %02d:0:0 1:00 D\n", mon_names[pDstStart->tm_mon], week_counts[startWeekCount-1][0], wday_names[pDstStart->tm_wday], week_counts[startWeekCount-1][1], pDstStart->tm_hour); pTmp += sprintf(pTmp, "Rule MYR minimum maximum - %s %s%s%s %02d:0:0 0 S\n", mon_names[pDstEnd->tm_mon], week_counts[endWeekCount-1][0], wday_names[pDstEnd->tm_wday], week_counts[endWeekCount-1][1], pDstEnd->tm_hour); pTmp += sprintf(pTmp, "Zone localtime %s MYR C%%sT\n", pTimeZone); } else { pTmp += sprintf(pTmp, "Zone localtime %s - CST\n", pTimeZone); } fp = fopen(__GLIBC_TZ_FILE_PATH__, "w+"); if (fp == NULL) { CMM_ERR("Open TZ file error!"); return CMM_ERROR; } if (fwrite(tzInfo, strlen(tzInfo), 1, fp) < 0) { CMM_ERR("Write TZ file error!"); fclose(fp); return CMM_ERROR; } fclose(fp); /* create /var/tmp/localtime */ util_execSystem(__FUNCTION__, "zic -d /var/tmp %s", __GLIBC_TZ_FILE_PATH__); #else int startWeekCount = 0, endWeekCount = 0; char tzInfo[BUFLEN_128] = {0}; char tmpTimeZone[BUFLEN_128] = {0}; char *pTmp = tzInfo; FILE *fp = NULL; /* Get the entire timezone */ cstr_strncpy(tmpTimeZone, pTimeZone, BUFLEN_128); tmpTimeZone[0] ^= 6; /* Change the leading symbol, '+' -> '-' or '-' -> '+' */ pTmp += sprintf(pTmp, "GMT%s", tmpTimeZone); /* DaylightSavings is enable */ if (pNewObj->daylightSavingsUsed) { /* set the week count as the UI wants */ startWeekCount = pNewObj->X_TP_DaylightSavingsStartWeekCount; endWeekCount = pNewObj->X_TP_DaylightSavingsEndWeekCount; /* Get the dst info, like "DST,Mmon.cnt.wday/hh,Mmon.cnt.wday/hh */ pTmp += sprintf(pTmp, "DST,M%d.%d.%d/%d,M%d.%d.%d/%d", \ pDstStart->tm_mon + 1, startWeekCount, pDstStart->tm_wday, pDstStart->tm_hour,\ pDstEnd->tm_mon + 1, endWeekCount, pDstEnd->tm_wday, pDstEnd->tm_hour); } *pTmp++ = '\n'; *pTmp = '\0'; /* Write the tzInfo to the file: /etc/TZ */ fp = fopen(__UCLIBC_TZ_FILE_PATH__, "w+"); if (fp == NULL) { CMM_ERR("Open TZ file error!"); return CMM_ERROR; } if (fwrite(tzInfo, strlen(tzInfo), 1, fp) < 0) { CMM_ERR("Write TZ file error!"); fclose(fp); return CMM_ERROR; } fclose(fp); #endif /* liuyuxuan add for parental control V2 */ memset(&tv, 0, sizeof(struct timeval)); memset(&tz, 0, sizeof(struct timezone)); gettimeofday(&tv, &tz); sscanf(pTimeZone, "%d:%d", &tzHour, &tzMin); if(tzMin > 0 && tzHour < 0) { tzMin = -tzMin; } tz.tz_minuteswest = -(MINUTES * tzHour + tzMin); settimeofday(setTv, &tz); /* liuyuxuan add end */ return CMM_OK; } 是在哪里设定夏令时
最新发布
10-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值