List of utility methods to do Random Date
String | generateRandomDate() generate Random Date Random r = new Random(); java.util.Calendar c = java.util.Calendar.getInstance(); c.set(java.util.Calendar.MONTH, Math.abs(r.nextInt()) % 12); c.set(java.util.Calendar.DAY_OF_MONTH, Math.abs(r.nextInt()) % 30); c.setLenient(true); return DATE_FORMAT.format(c.getTime()); |
String | getDateRandom() get Date Random String s = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()); return s; |
String | getDateRand(Date date) get Date Rand String str = sdf.format(date); double d = Math.random(); int t = 1000 + (int) (d * 9000.0D); return str + t; |
String | getDateRand() get Date Rand Calendar c = Calendar.getInstance(Locale.CHINA); Date d = c.getTime(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); return sdf.format(d) + (int) (Math.random() * 10); |
String | getDateRandomId() return a ID contruct on with the current date : sample : 20101223-4687 DateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.US); NumberFormat formatter = new DecimalFormat("00000"); String newDateId; do { Calendar today = Calendar.getInstance(); int daySec = today.get(Calendar.HOUR_OF_DAY) * 24 * 60 + today.get(Calendar.MINUTE) * 60 + today.get(Calendar.SECOND); String currentDate = format.format(today.getTime()); ... |
String | getRandomDate(Random ran, boolean idNewID) get Random Date if (ran == null) { return ""; int year = 0; if (idNewID) { year = 1900 + ran.nextInt(2007 - 1900); } else { year = 1 + ran.nextInt(99); ... |
String | getRandomDate() get Random Date long time = System.currentTimeMillis(); Date dat = new Date(time); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dat); java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); return format.format(gc.getTime()); |