LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-09-2009, 12:27 AM   #1
prakash.akumalla
Member
 
Registered: Jun 2008
Location: India
Posts: 109

Rep: Reputation: 15
Thumbs up Convert timeticks to hours


Hi,
Help me in converting timeticks to hours.

Thanks,
Prakash.
 
Old 01-09-2009, 12:46 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Q: Could you be a bit more specific, please?

Q: What *weren't* you able to find when you did a Google search?
 
Old 01-09-2009, 03:59 AM   #3
prakash.akumalla
Member
 
Registered: Jun 2008
Location: India
Posts: 109

Original Poster
Rep: Reputation: 15
I will get output of script in timeticks. I want to convert it to hours and present it.
How can we do so?

Thanks.
 
Old 01-09-2009, 04:08 AM   #4
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Rep: Reputation: Disabled
Could you explain that with an example? Still not clear what you exactly need.
 
Old 01-09-2009, 04:09 AM   #5
chakka.lokesh
Member
 
Registered: Mar 2008
Distribution: Ubuntu
Posts: 240

Rep: Reputation: 32
does the time command helps you?
 
Old 01-09-2009, 04:14 AM   #6
prakash.akumalla
Member
 
Registered: Jun 2008
Location: India
Posts: 109

Original Poster
Rep: Reputation: 15
Let me say in detail.
My script will calculate the system uptime in time ticks.
But,I want to display it as number of hours. So I want to change the output from time ticks to hours. How can i modify the output?

Thanks.
 
Old 01-09-2009, 04:18 AM   #7
chakka.lokesh
Member
 
Registered: Mar 2008
Distribution: Ubuntu
Posts: 240

Rep: Reputation: 32
Quote:
Originally Posted by prakash.akumalla View Post
Let me say in detail.
can you please be still more detail.

tell me which command you are using for getting the clock ticks inside the script.
 
Old 01-09-2009, 04:19 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Yes, an example of the input and the required output would be useful. If for "timeticks" you mean the number of seconds after some epoch, you can use the date command specifying the input with the -d option and formatting the output at your pleasure:
Code:
date -d @1231492552
the number of seconds since epoch must be preceded by @ otherwise the date command is not able to interpret the input correctly. The problem arises if your timeticks refer to an epoch different than the unix epoch (01-01-1970 01:00) so that you have to do some calculation to correct the discrepancy.

Edit: sorry, posted before seeing the reply above.

Last edited by colucix; 01-09-2009 at 04:21 AM.
 
Old 01-09-2009, 04:21 AM   #9
prakash.akumalla
Member
 
Registered: Jun 2008
Location: India
Posts: 109

Original Poster
Rep: Reputation: 15
date +%s will give the output in time ticks.
 
Old 01-09-2009, 04:22 AM   #10
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Rep: Reputation: Disabled
Are you talking of tick being 64th part of a second or so? If not then give real time example with what tick is and how your output will look like.
 
Old 01-09-2009, 04:41 AM   #11
chakka.lokesh
Member
 
Registered: Mar 2008
Distribution: Ubuntu
Posts: 240

Rep: Reputation: 32
Quote:
Originally Posted by prakash.akumalla View Post
date +%s will give the output in time ticks.
then can you use the command date +%R ?
 
Old 01-09-2009, 03:08 PM   #12
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Rep: Reputation: 35
you can convert the time ticks to seconds and then divide by 60 to get hours.
So the trick is to determine how many time ticks there are in a second and divide the time ticks by that value and then divide by 60 and you have it.
 
Old 01-09-2009, 10:44 PM   #13
chakka.lokesh
Member
 
Registered: Mar 2008
Distribution: Ubuntu
Posts: 240

Rep: Reputation: 32
Quote:
Originally Posted by john test View Post
you can convert the time ticks to seconds
usually, ticks means C.P.U. clock ticks. Me too taught in the beginning like this only. But the O.P. is using date +%s which will give the seconds. He is calling the seconds as ticks which is not the general intention.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Clock is 3 hours off mcd Ubuntu 2 01-20-2008 10:56 PM
I Need Help Fast!!! I Have Less Than 24 Hours bioagentice Linux - General 6 03-07-2005 10:33 AM
How many hours a day???????? JrLz General 15 04-13-2004 01:42 PM
clock changes hours by it self jct842 General 2 09-04-2002 11:26 PM
how many hours does it take ? sapilas Linux - Distributions 2 06-08-2002 11:26 AM


All times are GMT -5. The time now is 10:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration