convert total no of seconds in the format hour minutes and seconds
how to convert the integer no which represents the total no of seconds
int hour minute and seconds format.. is there any function..to do |
in what language ?
|
in awk shell scripting
|
They are no function I'm aware, but it is easy to implement:
Code:
function hms(s) |
is there any built in functuon
|
There are no time builtin functions in the standard awk / nawk, but gnu awk does have these extensions:
mktime strftime systime They are documented in the gawk manual page |
strftime converts but from since jan 1970..
how shall i |
you could make a script :
Code:
#!/bin/bash save this to a file and name it seconds.sh then type : su <your root password> chmod a+x seconds.sh then to execute it type : ./seconds.sh P.S: i didnt write this script , i found it before and sorry i cant remember where i got it from |
heema,
- the OP asked for awk and you sent a shell script. - there's absolutely no need to become root to chmod a file to be executable. |
Quote:
|
Quote:
Code:
print strftime("%H:%M:%S", 3620); |
Ugly, but works...
You seem correct, but AWK seems to make some strange assumptions.
apparently, 433 seconds translates into 01:07:11: Code:
echo |awk '{print strftime("%H:%M:%S", 433)}' Code:
echo |awk '{print strftime("%M:%S", 433)}' Code:
echo |awk '{print int(433/60)":"int(433%60)}' Code:
echo |awk '{print int(4000/60)":"int(4000%60)}' |
It looks like strftime() is sensitive to timezones. I played around with setting $TZ, and it affected the result of strftime(). I would post an example, but I'm not conversant enough in matters of timezones to give an example I know isn't nonsensical.
--- rod. |
I like this best from an earlier post in the same thread. It's simple, understandable and generic.
Quote:
|
Quote:
I forgot this part when reading up on strftome(): strftime([format [, timestamp [, utc-flag]]]) This function returns a string. It is similar to the function of the same name in ISO C. The time specified by timestamp is used to produce a string, based on the contents of the format string. If utc-flag is present and is either non-zero or non-null, the value is formatted as UTC. It works like a charm: Code:
echo |awk '{print strftime("%H:%M:%S", 433,1)}' |
echo "3661" | awk '{print int($0/3600),int($0%3600/60),$0%3600%60}'
|
All times are GMT -5. The time now is 12:11 AM. |