Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6784105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:56:58+00:00 2026-05-26T16:56:58+00:00

I fail to add seconds to Java Timestamp. I have this, but, it gives

  • 0

I fail to add seconds to Java Timestamp.

I have this, but, it gives me the same date:

int sec = 600;

java.sql.Timestamp ts_from_ws = new java.sql.Timestamp(retry_date);
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(ts_from_ws.getTime());
cal.add(Calendar.SECOND,sec);
java.sql.Timestamp ts_new_date_ws = new java.sql.Timestamp(cal.getTime().getTime());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:56:59+00:00Added an answer on May 26, 2026 at 4:56 pm

    The code you’ve got works for me. As a short but complete program:

    import java.util.*;
    import java.sql.*;
    
    public class Test {
        public static void main(String[] args) {
            long retryDate = System.currentTimeMillis();
    
            int sec = 600;
    
            Timestamp original = new Timestamp(retryDate);
            Calendar cal = Calendar.getInstance();
            cal.setTimeInMillis(original.getTime());
            cal.add(Calendar.SECOND, sec);
            Timestamp later = new Timestamp(cal.getTime().getTime());
    
            System.out.println(original);
            System.out.println(later);
        }
    }
    

    Output:

    2011-11-07 10:27:45.302
    2011-11-07 10:37:45.302
    

    Note the difference of 10 minutes, i.e. 600 seconds.

    Of course you lose the sub-millisecond precision this way, which may well not be ideal – and it goes against what I’m normally use a timestamp for in the first place – but it does add the seconds…

    Another option would be to just use Timestamp directly:

    Timestamp original = ...;
    Timestamp later = new Timestamp(original.getTime() + (sec * 1000L));
    later.setNanos(original.getNanos());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing multi-instance SQL 2008 cluster, and I'm trying to add Analysis
Im wondering how i could add a success or fail message to return at
I fail to understand why this code won't compile ExecutorService executor = new ScheduledThreadPoolExecutor(threads);
I fail to execute an SQL query with a with clause via ADODB and
Why does this code fail to display the category name Apples using the current
100['toString'] //does not fail 100.toString //fails why? 100.toString is not same as 100.toString() .
I have the following code that I expect to run successfully to completion but
I have a class A maintaining a list of objects class B. But each
I have a table of items, each of which has a date associated with
I have started the book Continuous Testing with Ruby (B2.0 printing), but am running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.