Java Random Time getRandomTimeOfDay()

Here you can find the source of getRandomTimeOfDay()

Description

get Random Time Of Day

License

Apache License

Declaration

public static String getRandomTimeOfDay() 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class Main {
    private static final SimpleDateFormat _TIME_FMT = new SimpleDateFormat("HH:mm");
    private static final Random _RAND = new Random(System.currentTimeMillis());

    public static String getRandomTimeOfDay() {
        long time = System.currentTimeMillis();
        int hrs = getRandomNumberBelow(4) * 6;
        int mins = getRandomNumberBelow(4) * 15;

        return _TIME_FMT.format(new Date(time + hrs * 3600000 + mins * 60000));
    }// w ww.  j  a  v a  2s .  c  o  m

    public static int getRandomNumberBelow(int limit) {
        return _RAND.nextInt(limit);
    }
}