随机数
Random rand = new Random();
int num = rand.nextInt(11)+21;
int randomWithMathRandom = (int) ((Math.random() * (max - min)) + min);
int randomWithMathRandom = (int) ((Math.random() * (3 - 1)) + 1);
验证码
String ZiMu = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGJKLZXCVBNM1234567890";
String result = "";
Random random = new Random();
for (int i = 0; i < 4; i++) {
int index = random.nextInt(ZiMu.length());
char c = ZiMu.charAt(index);
result += c;
}
System.out.print(result);
日期
Date dNow = new Date( );
SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss");
System.out.println("当前时间为: " + ft.format(dNow));
时区
public class test {
public static void main(String[] args) {
ZonedDateTime zonedDateTime = ZonedDateTime.now();
System.out.println(zonedDateTime);
}
}
工具类
hutool官网