Results 1 to 5 of 5
  1. #1
    sathish kumar is offline Member
    Join Date
    Sep 2010
    Posts
    3
    Rep Power
    0

    Default 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..

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default

    ?
    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...

  3. #3
    sathish kumar is offline Member
    Join Date
    Sep 2010
    Posts
    3
    Rep Power
    0

    Default

    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.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default

    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 < ?").

  5. #5
    sathish kumar is offline Member
    Join Date
    Sep 2010
    Posts
    3
    Rep Power
    0

Similar Threads

  1. how to get the seconds out of it
    By baktha.thalapathy in forum New To Java
    Replies: 15
    Last Post: 06-09-2010, 04:24 AM
  2. Replies: 3
    Last Post: 04-05-2010, 02:08 PM
  3. Convert microseconds to seconds
    By Basit56 in forum New To Java
    Replies: 4
    Last Post: 12-31-2009, 06:54 AM
  4. getting time elapsed in seconds
    By ali_sakar in forum New To Java
    Replies: 3
    Last Post: 03-06-2009, 09:37 AM
  5. Need help with calculate the number of seconds
    By ProUnbeatable in forum New To Java
    Replies: 5
    Last Post: 10-11-2008, 04:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •