Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert dayseconds in time of day 2

Status
Not open for further replies.

tini1208

Technical User
Feb 13, 2006
56
DE
hi all,

i've got a problem with the conversion of dayseconds to time of day.

i've converted the time of day 12:02:45 (hh:mm:ss) with:

Code:
gawk '{split ($3, time, ":")
       t_sec = time[1]*3600+time[2]*60+time[3]}'\
input > output

this works very well but what about the other way around? i don't know how to convert dayseconds (e.g. 34567) in the time of day 09:36:07. which command should i use? maybe join?

can anyboby help me??
 
A starting point:
Code:
...
h=int(t_sec/3600)
m=int((t_sec-3600*h)/60)
s=t_sec%60
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
thanks a lot for your answers.
i tried this

Code:
#! /bin/csh -f

#GPS Tagessekunde in Uhrzeit

set input = infile

echo $input

set output = outfile

echo $output

gawk '{h = int($1/3600)                                              \
       m = int(($1-3600*h)/60)                                       \
       s = $1-(3600*h)-(60*m)                                        \
       printf"%10.3f\t%10.6f\t%10.6f\t%10.3f\t%10s\t%2s\%2s\%2s\n"   \
       $1, $2, $3, $4, "1998 12 23", h, m, s                         \
}' $input > $output

but this there is an error

infile
outfile
gawk: cmd. line:5: $1, $2, $3, $4, "1998 12 23", h, m, s
gawk: cmd. line:5: ^ parse error

cheers.....
 
Stay away from broken csh:
Code:
#!/bin/ksh
#GPS Tagessekunde in Uhrzeit
input=infile
echo $input
output=outfile
echo $output
gawk '{h = int($1/3600)
       m = int(($1-3600*h)/60)
       s = $1-(3600*h)-(60*m)
       printf "%10.3f\t%10.6f\t%10.6f\t%10.3f\t%10s\t%2s\%2s\%2s\n",$1,$2,$3,$4,"1998 12 23",h,m,s
}' $input > $output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Or in your layout...

[tt]#! /bin/csh -f

#GPS Tagessekunde in Uhrzeit

set input = infile

echo $input

set output = outfile

echo $output

gawk '{h = int($1/3600) \
m = int(($1-3600*h)/60) \
s = $1-(3600*h)-(60*m) \
printf"%10.3f\t%10.6f\t%10.6f\t%10.3f\t%10s\t%2s\%2s\%2s\n"[red],[/red] \
$1, $2, $3, $4, "1998 12 23", h, m, s \
}' $input > $output[/tt]


HTH,

p5wizard
 
hi phv and p5wizard,

thank a lot for your good answers. i found the missing comma, when phv send the answer.

bye....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top