Java examples for java.util:Date Compare
returns a random date.
/**//from w w w. j a v a 2s .c om * Licensed under the Artistic License; you may not use this file * except in compliance with the License. * You may obtain a copy of the License at * * http://displaytag.sourceforge.net/license.html * * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ //package com.java2s; import java.util.Calendar; import java.util.Date; import java.util.Random; public class Main { /** * random number producer. */ private static Random random = new Random(); /** * returns a random date. * @return random date */ public static Date getRandomDate() { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 365 - random.nextInt(730)); return calendar.getTime(); } }