Java TimeUnit Usage getRandomDate()

Here you can find the source of getRandomDate()

Description

get Random Date

License

Open Source License

Declaration

public static Date getRandomDate() 

Method Source Code

//package com.java2s;
/**/*  w  w  w .  j  av  a 2 s .co m*/
 * Logspace
 * Copyright (c) 2015 Indoqa Software Design und Beratung GmbH. All rights reserved.
 * This program and the accompanying materials are made available under the terms of
 * the Eclipse Public License Version 1.0, which accompanies this distribution and
 * is available at http://www.eclipse.org/legal/epl-v10.html.
 */

import static java.util.concurrent.TimeUnit.DAYS;
import java.util.Date;
import java.util.Random;

public class Main {
    private static final Random RANDOM = new Random();

    public static Date getRandomDate() {
        long time = (long) (System.currentTimeMillis() - getRandomDouble() * DAYS.toMillis(3650));

        // set the milliseconds to 0
        time = time / 1000 * 1000;

        return new Date(time);
    }

    public static double getRandomDouble() {
        return RANDOM.nextDouble();
    }
}

Related

  1. getNormalizedIntervalStartTimestamp(long intervalLengthMillis, long currentTimestamp)
  2. getNowInSeconds()
  3. getOceanTime(final Date date)
  4. getPrettyTime(long duration)
  5. getQuantilesString(final Map quantilesValues)
  6. getReadableElapsedIntervalInSeconds(final long elapsedTimInMillis)
  7. getRemainingTimeString(int completedCount, int totalCount, long elapsed)
  8. getSeconds(long time)
  9. getSecondsDateDiff(Date dateStart)