Results 1 to 5 of 5
- 09-09-2010, 07:30 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 3
- Rep Power
- 0
Finding epoch seconds and separate yera,month,day,hr,min and seconds
Dear friends,
Using this below code, I got the timestamp..
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
return sdf.format(cal.getTime());
Output of this code is,
2010-09-09 11:21:07
Then I have split this things and got the year,month,day,hours,min and seconds separately. My need is using this details ( year,month,day,hours,min and seconds) I would like to know the epoch seconds.
Like wise using this epoch second I would like to know the year,month,day,hours,min and seconds separately.
Is there any functions available in java to resolve my needs.
Plzz help..
Thank you frds..
- 09-09-2010, 09:30 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
?
You have a Calendar, so why not get the year, month, day etc from that?
As for epoch seconds, you have the number of millis fro the epoch, so use that?
I must be missing something from your requirements...
- 09-09-2010, 10:32 AM #3
Member
- Join Date
- Sep 2010
- Posts
- 3
- Rep Power
- 0
thank u so much tolls for ur rply..
Ya I have seen that calender, but it wont solve my prob I hope.
I am doing command watcher application now,
This application will run the command each and every configured seconds and maintain its output to the database . I need to delete my old data ( For example I planned to delete the data which is there in the table 3 seconds before ).
I need to find the current timestamp , using it I need to find the epoch seconds. From this seconds i need to subtract the configured seconds ( for example 3 seconds ), then find the time stamp, using this new epoch second.
If any record is there in the table which is less then this timestamp then, I will delete it.
Now I hope u will understand my requirement.
Plzz give the solution/way to solve my prob frd..
Thank you so much.
- 09-09-2010, 10:52 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Get the current time (new java.util.Date()).
Get the time in millis from that (see API).
Subtract 3000 from that (3 seconds).
Create a new java.sql.Timestamp using that long value you've just calculated.
Stick that in your DELETE query ("DELETE FROM some_table WHERE my_timstamp < ?").
- 09-09-2010, 11:15 AM #5
Member
- Join Date
- Sep 2010
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
how to get the seconds out of it
By baktha.thalapathy in forum New To JavaReplies: 15Last Post: 06-09-2010, 03:24 AM -
a constructor to convert seconds to hours, min & seconds
By senca in forum New To JavaReplies: 3Last Post: 04-05-2010, 01:08 PM -
Convert microseconds to seconds
By Basit56 in forum New To JavaReplies: 4Last Post: 12-31-2009, 05:54 AM -
getting time elapsed in seconds
By ali_sakar in forum New To JavaReplies: 3Last Post: 03-06-2009, 08:37 AM -
Need help with calculate the number of seconds
By ProUnbeatable in forum New To JavaReplies: 5Last Post: 10-11-2008, 03:07 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks