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 9265363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:03:13+00:00 2026-06-18T14:03:13+00:00

I am trying create a seed point for Joda-Time. What I am trying to

  • 0

I am trying create a seed point for Joda-Time. What I am trying to achieve is that I will provide a seed datetime in Joda-Time, this should generate two different random datetime such that datetime1 is before than datetime2 and this datetime will generate values only for that specific hour of seed point.

e.g.

time- 18:00:00  followed by date-2013-02-13

Random1 - 2013-02-13 18:05:24 

Random2 - 2013-02-13 18:48:22

The time is received from one DB and the date is selected by the user. I need the two times randomly generated in the specified format
You can see that only the minutes and seconds will change, nothing else will be modified.

Is this possible? How can I achieve this?

  • 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-06-18T14:03:14+00:00Added an answer on June 18, 2026 at 2:03 pm

    The following code should do what you want. If it is possible that the minutes or seconds in your seed time are not zero, you should add .withMinuteOfHour(0).withSecondOfMinute(0) after the .parseDateTime(inputDateTime) method call.

    import java.util.Random;
    import org.joda.time.DateTime;
    import org.joda.time.format.DateTimeFormat;
    import org.joda.time.format.DateTimeFormatter;
    
    public class RandomTime {
    
    DateTimeFormatter inputFormat = DateTimeFormat.forPattern("HH:mm:ss yyyy-MM-dd");
    DateTimeFormatter outputFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    
    public TwoRandomTimes getRandomTimesFromSeed(String inputDateTime) {
        DateTime seed = inputFormat.parseDateTime(inputDateTime);
        Random random = new Random();
        int seconds1 = random.nextInt(3600);
        int seconds2 = random.nextInt(3600 - seconds1);
    
        DateTime time1 = new DateTime(seed).plusSeconds(seconds1);
        DateTime time2 = new DateTime(time1).plusSeconds(seconds2);
        return new TwoRandomTimes(time1, time2);
    }
    
    public class TwoRandomTimes {
        public final DateTime random1;
        public final DateTime random2;
    
        private TwoRandomTimes(DateTime time1, DateTime time2) {
            random1 = time1;
            random2 = time2;
        }
    
        @Override
        public String toString() {
            return "Random1 - " + outputFormat.print(random1) + "\nRandom2 - " + outputFormat.print(random2);
        }
    }
    
    public static void main(String[] args) {
        RandomTime rt = new RandomTime();
        System.out.println(rt.getRandomTimesFromSeed("18:00:00 2013-02-13"));
    }
    }
    

    In this solution the first random time is indeed used as the lower bound for the second random time. An alternative solution would be to just get two random dates and then sort them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create default seed records for every user that signs up to
I'm trying to create a function that takes two lists and selects an element
I am trying to create an agent-like object, that, given an two indices (agent
Trying to create a background-image slideshow and am getting this error... This is the
I have a lot of data that I'm trying to seed into a polymorphic
I have an XML file containing seed data that I'm trying to load into
I'm trying to create a seed file to populate my mongo database. The following
This has been stumping me for a while. I am trying to create a
In my seed file I am trying to create 3 users, 1 admin and
I am trying to create a simple web crawler using PHP that is capable

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.