I am just using this rule and it works quite well for me:
rule "Openhab Uptime"
when
System started
then
postUpdate(OH_Uptime, new DateTimeType(now.toString))
end
rule "Openhab Uptime readable"
when
Item OH_Uptime changed or
Time cron "1 1 * * * ?"
then
var String tmp
if(OH_Uptime != NULL) {
var DateTime dateTime_OH_Uptime = new DateTime((OH_Uptime.state as DateTimeType).calendar.timeInMillis)
var diff = now.millis - dateTime_OH_Uptime.millis
//http://stackoverflow.com/questions/13018550/time-since-ago-library-for-android-java
val Number SECOND_MILLIS = 1000;
val Number MINUTE_MILLIS = 60 * SECOND_MILLIS;
val Number HOUR_MILLIS = 60 * MINUTE_MILLIS;
val Number DAY_MILLIS = 24 * HOUR_MILLIS;
if (diff < MINUTE_MILLIS) {
tmp = "just now";
} else if (diff < 2 * MINUTE_MILLIS) {
tmp = "a minute";
} else if (diff < 50 * MINUTE_MILLIS) {
tmp = String::format("%.2f", diff / MINUTE_MILLIS) + " Minutes";
} else if (diff < 90 * MINUTE_MILLIS) {
tmp = "an hour ago";
} else if (diff < 24 * HOUR_MILLIS) {
tmp = String::format("%.2f", diff / HOUR_MILLIS) + " Hours";
} else if (diff < 48 * HOUR_MILLIS) {
tmp = "since yesterday";
} else {
tmp = String::format("%.1f", diff / DAY_MILLIS) + " Days";
}
postUpdate(OH_Uptime_HumanReadable, tmp)
}
end