为什么这样的操作:
std::cout << (-7 % 3) << std::endl;
std::cout << (7 % -3) << std::endl;
Run Code Online (Sandbox Code Playgroud)
给出不同的结果?
-1
1
Run Code Online (Sandbox Code Playgroud) 如何从对象中提取年,月,日,小时,分钟,秒和毫秒std::chrono::time_point?
我只看到了如何从a中提取例如秒的总量的示例duration.
我正在尝试编写一个Date类来尝试学习C++.
我正在尝试找到一个算法来添加或减去日期到日期,其中Day从1开始,Month从1开始.它被证明是非常复杂的,并且谷歌没有出现太多,
有谁知道这样做的算法?
输入:自0001年1月1日起的秒数
输出:此期间的全年数
我开发了一种我认为不是最佳解决方案的算法.我认为应该有一个不涉及循环的解决方案.有关算法的信息,请参阅代码块1. A)确定天数和B)根据闰年从迭代年份中迭代减去366或365,同时增加年份总数
这并不像Divide DayCount那样简单365.2425和截断,因为我们在1月1日遇到了失败点,0002(31536000秒/(365.2425*24*60*60))= 0.99934.
从0001年1月1日上午12:00开始,从非循环方法中提取年数的任何想法?
我需要弄明白这一点,因为我需要一个长时间嵌入的日期(存储秒数),以便我可以用1秒的精度跟踪多达1200万.
代码块1 - 从秒数(包括闰年)获得年数的低效算法
Dim Days, Years As Integer
'get Days
Days = Ticks * (1 / 24) * (1 / 60) * (1 / 60) 'Ticks = Seconds from Year 1, January 1
'get years by counting up from the beginning
Years = 0
While True
'if leap year
If (Year Mod 4 = 0) AndAlso (Year Mod 100 <> 0) OrElse (Year Mod 400 = 0) Then
If Days >= …Run Code Online (Sandbox Code Playgroud)