package com.hqb360.uic.biz.point.impl; import com.hqb360.common.lang.DateUtil; import java.util.Date; /** 生成随机时间 * Created with IntelliJ IDEA. * User: * Date: 14-3-25 * Time: 上午10:59 */ public class TestDate { private static Date randomDate(Date startTime, Date endTime) { long randomDistance = random(startTime.getTime(), endTime.getTime()); return new Date(randomDistance); } private static long random(long begin, long end) { long distance = begin + (long) (Math.random() * (end - begin)); if (distance == begin || distance == end) { return random(begin, end); } return distance; } public static void main(String[] args) { // 当天的开始时间 Date dateOfStart = DateUtil.getDateOfStart(new Date()); // 当天的结束时间 Date dateOfEnd = DateUtil.getDateOfEnd(new Date()); Date date = randomDate(dateOfStart, dateOfEnd); System.out.println("生成的随机时间是:" +date); } }