java获取随机时间的源码片段-tozgb的博客
2019年05月16日
原文
将写内容过程中重要的一些内容做个记录,如下资料是关于java获取随机时间的片段的内容。
import java.text.parseexception;
import java.text.simpledateformat; import java.util.date; public class getrandomtiem { public static void main(string []args){ simpledateformat format = new simpledateformat("hh:mm:ss"); date randomdate=randomdate("00:00:00","24:59:59"); string randomdats="shi"+randomdate.gethours()+"f"+randomdate.getminutes()+"m"+randomdate.getseconds(); system.out.println(randomdats); } private static date randomdate(string begindate,string enddate ){ try { simpledateformat format = new simpledateformat("hh:mm:ss"); if(start.gettime() >= end.gettime()){ return null; } long date = random(start.gettime(),end.gettime()); return new date(date); } catch (exception e) { e.printstacktrace(); } return null; } private static long random(long begin,long end){ if(rtn == begin || rtn == end){ return random(begin,end); } return rtn; } }