因为arduino上好像没有类似的库,所以自己实现了一下这个算法,代码在下面,示例代码是python的,其他语言稍微改一下即可(对于months那个数组可能需要一个if来判断下2月的天数,示例代码里简写了判断)
UNIX_time = 1452342340 year = 1970 + (UNIX_time/86400-1096)/1461*4+3+(UNIX_time/86400-1096)%1461/365 yearday = (UNIX_time/86400-1096)%1461%365+1 if (UNIX_time/86400-1096)%1461/365 == 4: year-=1 yearday = 366 months=[31, (28,29)[(UNIX_time/86400-1096)%1461/365 >= 3], 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] month=0 while yearday > 0: yearday-=months[month] month+=1 day = yearday+months[month-1] hour = (UNIX_time % 86400) / 3600 minute = (UNIX_time % 3600) / 60 second = UNIX_time % 60 print 'Time is %s-%s-%s %s:%s:%s' % (year, month, day, hour, minute, second)