package math;import java.util.Date;public class Testrandom extends Thread  {
public static void main(String[] args) {
mythread my = new mythread();
Date dt = new Date();
String a=dt.toLocaleString();
System.out.println(a);
my.start();
}
}
class mythread extends Thread{
public void run(){
while(true){
try{Thread.sleep(60000*5);
int [] num = new int[1];
for(int i=0;i<num.length;i++){
num[i] = (int)(Math.random()*(27-0+1)+0); 
System.out.print(num[i]+" ");
}
}catch(InterruptedException e){}
System.out.println("搞不定怎么办");
}
}
}

解决方案 »

  1.   

    你在main里边判断哈当前时间,然后执行不就可以了?或者在while(hour==12)执行,这样应该都可以的!
      

  2.   

    那个hour的值怎么邓得呢?
      

  3.   


      Calendar c = Calendar.getInstance();
      int hours = c.get(Calendar.HOUR_OF_DAY);
      

  4.   


     Calendar c = Calendar.getInstance();
    if( c.get(Calendar.HOUR_OF_DAY)==12)
    {
     //do what you want}
      

  5.   

    取到了时间的字符串,再用string类里的方法去解析它,能获取到小时的.
      

  6.   

    java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyyMMdd"); 
    java.util.Date currentTime = new java.util.Date(); 
    System.out.print(formatter.format(currentTime));
    String today=formatter.format(currentTime);
    String hour=xcrq.substring(5,7);
      

  7.   

    java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd"); 
            java.util.Date currentTime = new java.util.Date(); 
            System.out.print(formatter.format(currentTime));
            String today=formatter.format(currentTime);
    String hour=xcrq.substring(5,7);
      

  8.   

    java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyyMMdd"); 
            java.util.Date currentTime = new java.util.Date(); 
            System.out.print(formatter.format(currentTime));
            String today=formatter.format(currentTime);
    String hour=today.substring(4,6);
    然后再判断就OK了