Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

randpm years java

long aDay = TimeUnit.DAYS.toMillis(1);
long now = new Date().getTime();
Date hundredYearsAgo = new Date(now - aDay * 365 * 100);
Date tenDaysAgo = new Date(now - aDay * 10);
Date random = LegacyRandomDateTimes.between(hundredYearsAgo, tenDaysAgo);
assertThat(random).isBetween(hundredYearsAgo, tenDaysAgo);
Comment

random years java

import java.time.LocalDate;

public class RandomDates {
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            LocalDate randomDate = createRandomDate(1900, 2000);
            System.out.println(randomDate);
        }
    }

    public static int createRandomIntBetween(int start, int end) {
        return start + (int) Math.round(Math.random() * (end - start));
    }

    public static LocalDate createRandomDate(int startYear, int endYear) {
        int day = createRandomIntBetween(1, 28);
        int month = createRandomIntBetween(1, 12);
        int year = createRandomIntBetween(startYear, endYear);
        return LocalDate.of(year, month, day);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: group all keys with same values in a hashmap java 
Java :: is type java 
Java :: maximum valid parentheses 
Java :: gif to blob java 
Java :: initialcontext tomcat bug 
Java :: rstudio boxplot coloring 
Java :: function name in java 
Java :: what does put extra do? 
Java :: Java Stack class push() method 
Java :: rerun main method 
Java :: tree algorithm example 
Java :: java 11 read file line by line 
Java :: Write program for problem 1 such that every regex runs as its own thread in java 
Java :: print map in java log 
Java :: c# param.ExStyle equivalent in java 
Java :: set bean properties 
Java :: how many public classes can be allowed in java 
Java :: java add forward / at the end of not present 
Java :: what does this means error: cannot find symbol StorageRef.child(mUser()).putFile(imageUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot() 
Java :: least significant bit java 
Java :: javax.ws.rs.core.response readentity not found 
Java :: Create all possible substrings of a string java 
Java :: read CSV file and map it to bean java 
Java :: JVM signatures 
Java :: Which type of Exception will be thrown by forName() method 
Java :: treeset order in java 
Java :: activity selection java solution 
Java :: how to set background color in jframe in java 
Java :: getcokor from drawable in java android studio 
Java :: Java program to calculate cubic capacity cc in bikes 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =