get Random Time - Android java.util

Android examples for java.util:Random

Description

get Random Time

Demo Code


//package com.java2s;

import java.util.Calendar;

import java.util.Random;

public class Main {
    public static long getRandomTime() {
        Calendar time = Calendar.getInstance();
        int day = 1 + random(time.get(Calendar.DAY_OF_MONTH));
        int hour = 1 + random(22);
        int minute = 1 + random(56);
        time.set(Calendar.DAY_OF_MONTH, day);
        time.set(Calendar.HOUR_OF_DAY, hour);
        time.set(Calendar.MINUTE, minute);
        return time.getTimeInMillis();
    }/*ww  w. java2  s  .  com*/

    public static int random(int n) {
        return (new Random()).nextInt(n);
    }
}

Related Tutorials