小编swo*_*ert的帖子

有限嵌入式设备上的Epoch秒到期转换

我试图找出从纪元秒(自NTP纪元1900-01-01 00:00)转换为日期时间字符串(MM/DD/YY,hh:mm:ss)的最佳方法,没有任何库/模块/外部功能,因为它们在嵌入式设备上不可用.

我的第一个想法是查看Python datetime模块源代码,但这对我来说并不是很有用.

我在Python中的初始尝试使用了自0001-01-01以来的日期转换,使用了getDateFromJulianDayC++源代码改编为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)

python embedded datetime epoch ntp

5
推荐指数
2
解决办法
2905
查看次数

标签 统计

datetime ×1

embedded ×1

epoch ×1

ntp ×1

python ×1