The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Generating files with time interval of fifteen minutes aajan Shell Programming and Scripting 0 09-24-2007 10:54 PM
how to display time in minutes n seconds... santy Shell Programming and Scripting 1 08-23-2006 07:18 AM
Help setting PS1 prompt to include current time m223464 Shell Programming and Scripting 3 11-28-2005 09:59 PM
Substituting variable with current time jhansrod Shell Programming and Scripting 4 11-20-2005 05:20 PM
How can I create a file with current time - 60 minutes DaveyTN Shell Programming and Scripting 4 10-05-2005 05:17 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-21-2007
gptavares's Avatar
Registered User
 

Join Date: Dec 2003
Posts: 5
Adding # minutes to current time...

Hi all,
Looking for a way to add lets say 10 minutes to the current time output should look like 7:15 AM or 7:15 PM. I know that gdate could do this for me but unfortunately its not available on the system I'm working on. So if any one know any way I can accomplish this using the date command it would be great.

Thanks,
--GT
Reply With Quote
Forum Sponsor
  #2  
Old 06-21-2007
kamitsin's Avatar
Registered User
 

Join Date: Nov 2006
Location: /dev/null
Posts: 177
$ date
Thu Jun 21 22:12:54 IST 2007

Code:
$ perl -e 'print scalar localtime time + 600'
Thu Jun 21 22:22:59 2007
Reply With Quote
  #3  
Old 06-21-2007
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
Code:
#!/bin/ksh
add_min()
{
	perl -e '
	     $tm = $ARGV[0];
	     $tm *= 60;
	     ($sec,$min,$hour,$day,$mon,$yr,$wday,$yday,$dntcare)=localtime(time + $tm);
	printf("%2d:%2d:%2d\n", $hour, $min, $sec);  
	       ' $1
}	

add_min 10
Reply With Quote
  #4  
Old 06-21-2007
gptavares's Avatar
Registered User
 

Join Date: Dec 2003
Posts: 5
I really like this one liner, perl -e 'print scalar localtime time + 600' however the format of the output needs to look like 1:39 PM.... can this be done with perl?

P.S. Thanks for the quick responses...

Last edited by gptavares; 06-21-2007 at 11:07 AM.
Reply With Quote
  #5  
Old 06-21-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
Try:
perl -e '@d=localtime time() + 600; printf "%02d:%02d%s\n",$d[2]%12,$d[1],("AM","PM")[$d[2]/12]'
Reply With Quote
  #6  
Old 06-21-2007
gptavares's Avatar
Registered User
 

Join Date: Dec 2003
Posts: 5
Perfect, thanks Perderabo... and everyone else...
Reply With Quote
  #7  
Old 06-21-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,580
gnu awk
Code:
awk 'BEGIN{print strftime("%c %p",systime()+600)}'
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0