diff --git a/commands/hwclock.c b/commands/hwclock.c index a1f5293..49569a9 100644 --- a/commands/hwclock.c +++ b/commands/hwclock.c @@ -138,9 +138,7 @@ snprintf(t, 12, "%lu", time); setenv(env_name, t); } else { - printf("%02d:%02d:%02d %02d-%02d-%04d\n", - tm.tm_hour, tm.tm_min, tm.tm_sec, - tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900); + printf("%s\n", time_str(&tm)); } return 0; diff --git a/common/date.c b/common/date.c index 6b6b7ab..129192e 100644 --- a/common/date.c +++ b/common/date.c @@ -148,3 +148,21 @@ )*60 + min /* now have minutes */ )*60 + sec; /* finally seconds */ } + +const char *time_str(struct rtc_time *tm) +{ + const char *weekdays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; + const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", + "Sep", "Oct", "Nov", "Dec" }; + static char buf[128]; + + sprintf(buf, "%s %02d %s %4d %02d:%02d:%02d", + weekdays[tm->tm_wday], + tm->tm_mday, + months[tm->tm_mon], + tm->tm_year + 1900, + tm->tm_hour, + tm->tm_min, + tm->tm_sec); + return buf; +} diff --git a/include/rtc.h b/include/rtc.h index e2414fb..600dc46 100644 --- a/include/rtc.h +++ b/include/rtc.h @@ -55,4 +55,6 @@ extern struct rtc_device *rtc_lookup(const char *name); +const char *time_str(struct rtc_time *tm); + #endif /* _RTC_H_ */