File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
Adding seconds to time
Will Paul
Greenhorn
Joined: May 27, 2005
Posts: 8
posted
Nov 22, 2005 23:35:00
0
Not sure if this is beginner or intermediate. How can I add seconds to a time value as in hh:mm:ss? For example, 30 (seconds) + 10:30:05
[ November 22, 2005: Message edited by: Will Paul ]
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
Nov 23, 2005 02:13:00
0
one of the ways
System.out.println("now = "+new java.text.SimpleDateFormat("hh:mm:ss").format(new java.util.Date())); System.out.println("now + 30 = "+new java.text.SimpleDateFormat("hh:mm:ss").format(new java.util.Date(System.currentTimeMillis()+30000)));
Jeff Albertson
Ranch Hand
Joined: Sep 16, 2005
Posts: 1780
posted
Nov 23, 2005 06:39:00
0
Here's another way, if you are using calendar:
import java.util.*; import java.text.*; public class Test { public static void main(String[] args) throws ParseException { DateFormat df = new SimpleDateFormat("hh:mm:ss a"); Date date = df.parse("11:59:45 AM"); System.out.println("time, after round trip: " + df.format(date)); Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.SECOND, 30); date = cal.getTime(); System.out.println("time+30: " + df.format(date)); } }
There is no emoticon for what I am feeling!
I agree. Here's the link:
http://jrebel.com/download
subject: Adding seconds to time
Similar Threads
dilbert
Refresh image
Difference between '+' and concat in string
Session variables are not getting storred
Cool Names for Bands/Artists
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter