我从1970年1月1日00:00开始的秒数为纳秒的int64,我试图将其转换为月/日/年/星期.
迭代地执行此操作很容易,我有这个工作,但我想公式化.我正在寻找实际的数学.
我试图找出从纪元秒(自NTP纪元1900-01-01 00:00)转换为日期时间字符串(MM/DD/YY,hh:mm:ss)的最佳方法,没有任何库/模块/外部功能,因为它们在嵌入式设备上不可用.
我的第一个想法是查看Python datetime模块源代码,但这对我来说并不是很有用.
我在Python中的初始尝试使用了自0001-01-01以来的日期转换,使用了getDateFromJulianDay从C++源代码改编为Python ,并结合模运算来获取时间.它有效,但有更好的方法吗?
def getDateFromJulianDay(julianDay):
# Gregorian calendar starting from October 15, 1582
# This algorithm is from:
# Henry F. Fliegel and Thomas C. van Flandern. 1968.
# Letters to the editor:
# a machine algorithm for processing calendar dates.
# Commun. ACM 11, 10 (October 1968), 657-. DOI=10.1145/364096.364097
# http://doi.acm.org/10.1145/364096.364097
ell = julianDay + 68569;
n = (4 * ell) / 146097;
ell = ell - (146097 * n …Run Code Online (Sandbox Code Playgroud) 首先,我知道这个问题有点被问及/在这里得到解答:用数学方式从unix-timestamp计算天数?.
我需要一个自定义函数/公式.所以它只返回ISO格式的日期."YYYY-MM-DD".
eg. 1316278442 = 2011-09-17
Run Code Online (Sandbox Code Playgroud)
由Ext编辑!这是错的!请不要读这个.
我整天都在这里!我唯一能成功的就是一周中的哪一天.
$一周中的某天=($时间戳/ 86400)%7; //这里1是星期六,7星期五
速度是问题,这就是我不想使用的原因 date('Y-m-d',$timestamp);
如果你无法帮助我自定义功能或公式,至少可以给我一个更好的解释如何做到这一点.这是用多种语言完成的,必须有人知道如何做到这一点.
预先感谢您的帮助.
我正在为我的大学做一个项目。任务是打印当前日期和时间。我成功地创建了一个打印数字的子程序,我现在需要的只是获取日期。我试过这种方法:
%define RTCaddress 0x70
%define RTCdata 0x71
;Get time and date from RTC
.l1: mov al,10 ;Get RTC register A
out RTCaddress,al
in al,RTCdata
test al,0x80 ;Is update in progress?
jne .l1 ; yes, wait
mov al,0 ;Get seconds (00 to 59)
out RTCaddress,al
in al,RTCdata
mov [RTCtimeSecond],al
Run Code Online (Sandbox Code Playgroud)
但只是打电话:
.l1: mov al,10 ;Get RTC register A
out RTCaddress,al
Run Code Online (Sandbox Code Playgroud)
足以导致崩溃。您知道如何解决这种方法吗,或者我可以使用任何不同的方法。我正在 Linux 64 位上使用 Nasm。
继续我尝试创建一个DateTime类,我试图在我的函数中存储"epoch"时间:
void DateTime::processComponents(int month, int day, int year,
int hour, int minute, int second) {
struct tm time;
time.tm_hour = hour;
time.tm_min = minute;
time.tm_sec = second;
time.tm_mday = day;
time.tm_mon = month;
time.tm_year = year - 1900;
ticks_ = mktime(&time);
processTm(time);
}
void DateTime::processTm(struct tm time) {
second_ = time.tm_sec;
minute_ = time.tm_min;
hour_ = time.tm_hour;
weekday_ = time.tm_wday;
monthday_ = time.tm_mday;
yearday_ = time.tm_yday;
month_ = time.tm_mon;
year_ = time.tm_year + 1900;
}
Run Code Online (Sandbox Code Playgroud)
对于任意日期processComponents(5,5,1990,1,23,45)(1990年6月6日上午1:23:45),它正确地设置所有值并按预期设置. …