in reply to Time Conversion
/proc/uptime contains the number of seconds that the system has been up. You can use gmtime() to treat this as the number of seconds since the beginning of the epoch, January 1, 1970. The "date" will have the hour, minutes, and seconds. If you want months, you can use the month and day of the month minus 1. If you want just days, the day of the year works.
# Use the function from the previous reply # to read the value from /proc/uptime my $uptime = uptime(); my @tm = gmtime($uptime); my $string = sprintf("%03d %02d:%02d:%02d", $tm[7], $tm[2], $tm[1], $t +m[0]);
For longer spans, you will need to use the year (minus 70). Also, you will need to worry about leap years; 1972 was a leap year and adds an extra day. For this, you might want to find a module for handling intervals. DateTime::Duration is a good choice.
|
|---|