2.给出距离1900年1月1日的天数,求日期
1 #include <iostream> 2 #include <assert.h> 3 4 5 //判断是否闰年 6 bool IsLeapYear(unsigned int year) 7 { 8 if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) 9 { 10 return true; 11 } 12 else 13 { 14 return false; 15 } 16 } 17 18 //根据一年中的第几天(0起始),返回月份(1起始),并且置天数为其在本月的索引(0起始) 19 unsigned int GetMonthByDay(unsigned int &day, bool leap) 20 { 21 assert(day < (leap ? 366 : 365)); 22 static unsigned int monthtable[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 23 monthtable[1] = leap ? 29 : 28; 24 25 unsigned int month = 0; 26 unsigned int count = 0; 27 unsigned int n = day; 28 29 do 30 { 31 n = day - count; 32 count += monthtable[month++]; 33 } while (day >= count); 34 day = n; 35 return month; 36 } 37 38 //距离1900年1月1日的天数(0起始),返回年,并且置天数为其在本年的索引(0起始) 39 unsigned int GetYearByDay(unsigned int &day) 40 { 41 unsigned int Y = day / 365; 42 int D = day % 365; 43 int YY = Y - 1; 44 D -= YY / 4; 45 D += YY / 100; 46 D -= (YY + 300) / 400; 47 while (D < 0) 48 { 49 Y--; 50 D += IsLeapYear(Y + 1900) ? 366 : 365; 51 } 52 day = D; 53 return Y + 1900; 54 } 55 56 //距离1900年1月1日的天数(0起始),计算这一天的日期(年,月,日)(1起始)。 57 void foo(unsigned int &day, unsigned int &year, unsigned int &month) 58 { 59 year = GetYearByDay(day); 60 month = GetMonthByDay(day, IsLeapYear(year)); 61 day += 1; 62 } 63 64 int main() 65 { 66 unsigned int day = 42696; 67 unsigned int year = 0; 68 unsigned int month = 0; 69 foo(day, year, month); 70 std::cout << year << "/" << month << "/" << day << std::endl; 71 getchar(); 72 return 0; 73 }
转载于:https://www.cnblogs.com/csqtech/p/6142186.html
2.给出距离1900年1月1日的天数,求日期相关推荐
- 现在距离1970年1月1日的天数
#include<stdio.h> #include<time.h> int main() { time_t t; t=time(0)/60/60/24: printf(&qu ...
- Java——计算用户输入的日期离1900年1月1日相距多少天
题目:计算用户输入的日期离1900年1月1日相距多少天 解析: 用户输入日期,所以需要使用Scanner获取用户键盘输入数据 计算输入日期距离xxxx多少天,所以就是获取相差年份的天数+相差月份天数+ ...
- 计算用户输入的日期距离1990年1月1日相距多少天
public static void main(String[] args) {//计算用户输入的日期距离1990年1月1日相距多少天Scanner sc = new Scanner(System.i ...
- python程序设计请计算从公元1年1月_使用Python计算今天距离公元1年1月1日的天数...
最近,在做一个项目时,要求计算当天距离公元1年1月1日的天数(含公元1年1月1日),耗费了我将近半个小时时间.梳理一下思路,以备不时之需. 计算天数Python实现 距离公元1年1月1日的天数?要一天 ...
- 题目:输入某年某月某日,判断当日是星期几? 提示:1900年1月1日为星期一
题目:输入某年某月某日,判断当日是星期几? 提示:1900年1月1日为星期一 package com.lc.chapter032;import java.util.Calendar; import j ...
- C语言/打印日历,用户输入年分和月份两个变量,系统计算该月份的1号是星期几,并计算该月有多少天。最后打印出该日历。已知:1900年1月1日是星期一
打印日历,用户输入年分和月份两个变量,系统计算该月份的1号是星期几,并计算该月有多少天.最后打印出该日历.已知:1900年1月1日是星期一 C语言 #define _CRT_SECURE_NO_WAR ...
- 随机输入日期计算星期几(1900年1月1日为基础)
已知,1900年1月1日是星期1,用户随机输入年月日,计算星期几 第一版,纯python基础代码实现 1 year=int(input('year')) 2 month=int(input('mont ...
- 计算用户输入的日期离1900年1月1日相距多少天。日期要大于1900(注意闰年,每个月份天数不一样)
import java.util.Scanner;public class test {public static void main(String[] args) {//计算用户输入的日期离1900 ...
- 2021高考成绩什么时候可以查询日照,成绩提前公布!2021省考成绩查询时间出了!最早4月15日!...
成绩提前公布!2021省考成绩查询时间出了!最早4月15日! 成绩提前公布!2021省考成绩查询时间出了!最早4月15日! <教育部关于做好2021届全国普通高校毕业生就业创业工作的通知> ...
最新文章
- 倒车辅助Park Assist
- 湖大和厦大计算机专硕6,【图片】一战厦大计算机上岸,经验帖。慢更【考研吧】_百度贴吧...
- Subversion 1.7 Eclipse integration in Ubuntu12(转载)
- 1003 Express Mail Taking
- python十进制转换_Python进制转换
- C语言之数据类型,C语言之数据类型
- Win10清理C盘垃圾
- Linux - history命令详解
- Linux修改时间 修改时区 | Linux时间校准
- 运维自动化之殇 | 高效运维最佳实践05
- 《路由器开发 - 路由器刷机指南》优酷路由宝 YK-L1刷机
- html中易混淆的offset、client、scroll
- 使用CVXQUAD时出现,函数或变量 ‘op_rel_entr_epi_cone‘ 无法识别。
- springMVC+阿里云API = 实现发送手机验证码短信
- 嵌入式开发(S5PV210)——u-boot的头文件包含问题
- PHP-FFMpeg 安装
- No.026<软考>《(高项)备考大全》【第10章】项目沟通和干系人管理(第2部分-干系人管理)
- Shopee:Shopee的零食柜(C++语言实现)
- 计算机服务怎么打开flash,windows无法启动flash helper service怎么办?
- 减法公式运算法则_减法的运算法则是什么