我想要做的是将纪元时间(自1970年1月1日午夜以来的秒数)转换为"实际"时间(m/d/yh:m:s)
到目前为止,我有以下算法,对我来说感觉有点难看:
void DateTime::splitTicks(time_t time) {
seconds = time % 60;
time /= 60;
minutes = time % 60;
time /= 60;
hours = time % 24;
time /= 24;
year = DateTime::reduceDaysToYear(time);
month = DateTime::reduceDaysToMonths(time,year);
day = int(time);
}
int DateTime::reduceDaysToYear(time_t &days) {
int year;
for (year=1970;days>daysInYear(year);year++) {
days -= daysInYear(year);
}
return year;
}
int DateTime::reduceDaysToMonths(time_t &days,int year) {
int month;
for (month=0;days>daysInMonth(month,year);month++)
days -= daysInMonth(month,year);
return month;
}
Run Code Online (Sandbox Code Playgroud)
你可以假设成员seconds,minutes,hours,month, …
我想知道如何用基本的Python(不使用库)解决这个问题:How can Icalculate When one's 10000 day after thebirth will (/would be)?
例如,给定星期一 19/05/2008,所需的日期是星期五 05/10/2035(根据https://www.durrans.com/projects/calc/10000/index.html?dob=19%2F5% 2F2008&e=mc2 )
到目前为止我已经完成了以下脚本:
years = range(2000, 2050)
lst_days = []
count = 0
tot_days = 0
for year in years:
if((year % 400 == 0) or (year % 100 != 0) and (year % 4 == 0)):
lst_days.append(366)
else:
lst_days.append(365)
while tot_days <= 10000:
tot_days = tot_days + lst_days[count]
count = count+1
print(count)
Run Code Online (Sandbox Code Playgroud)
它会估计该人生日 10,000 天后的年龄(对于 2000 年之后出生的人)。但我该如何继续呢?
是否有快速,低垃圾的方式来做到这一点?我不能只做简单的模数运算,因为它不考虑闰秒和其他日期/时间有趣的业务.
所以我正在编写一个程序,我想要一些用户输入.假设我们定义一个int; 叫做年龄.如果用户是成年人(比方说30岁以上),我希望程序将所有非正式的"你"交换为"正式"你的(许多语言,如法语,有这种区别,想到vous vs tu)在荷兰语中,"u"是正式的而不是"je".
这样做最简洁的方法是什么?我现在有这个(使用今天的日期,2015年9月18日):
string abc;
if (2015 - year of birth > 30) {
abc = "u";
}
else {
abc = "je";
}
if (2015 - year of birth == 30) {
if ( September - month of birth > 0) {
abc = "u";
}
else {
abc = "je";
}
}
if (2015 - year of birth == 30) {
if (September - month of birth == 0) {
if (18 - day of birth …Run Code Online (Sandbox Code Playgroud)