1.获取当前日期
import java.util.Date;
import java.text.SimpleDateFormat;
public class DateDemo
{
public static void main(String[] args){
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
String now = sdf.format(date);
System.out.println(now);
}
}
2.获取随机数
import java.util.Random;
public class RandomDemo
{
public static void main(String[] args){
Random random = new Random();
int i = random.nextInt(10);
System.out.println(i);
}
}