public static void main(String[] args) throws ParseException { Date date1 = new Date(); //now Date date2 = new Date(0); //计算机元年 Date date3 = new Date(Long.MAX_VALUE);//毫秒数 Date date4 = new Date(Long.MIN_VALUE); System.out.println(date1); //Fri Jul 14 15:43:07 CST 2023 System.out.println(date2); //Thu Jan 01 08:00:00 CST 1970 System.out.println(date3); //Sun Aug 17 15:12:55 CST 292278994 System.out.println(date4); //Mon Dec 03 00:47:04 CST 292269055 SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "yyy-MM-dd"); String format = simpleDateFormat.format(date3); //日期转字符串 System.out.println(format) ; // 292278994-08-17 Date date = simpleDateFormat.parse("2009-09-01");//字符串转日期 System.out.println(date);//Tue Sep 01 00:00:00 CST 2009
//不能直接同Date("2023","7","14"),用Calendar转成Date对象
//晚于Date 出现,内部有方法转成Date对象
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR,2023);
calendar.set(Calendar.MONTH,7-1); //要减1
calendar.set(Calendar.DATE,14);
Date date5 = calendar.getTime();
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat( "yyy-MM-dd");
String format1 = simpleDateFormat1.format(date5);
System.out.println(format1); //2023-07-14
}
Random
public static void main(String[] args) { double sqrt= Math.sqrt(5); System.out.println(sqrt); //2.23606797749979 System.out.println((int)(3*Math.random()));//0 1 2 中的一个 Random random = new Random(); System.out.println(random.nextInt(3));// [0,3) 返回下一个伪随机数 System.out.println(random.nextInt()); // -2^31 ~ 2^31-1 1003074860 System.out.println(random.nextDouble()); //[0.0,1.0) 0.41192985312663155 System.out.println(random.nextBoolean()); //false Random random1 = new Random(12112);//种子初始值 用同一个种子值来初始化两个Random对象,然后用每个对象调用相同的方法,得到的随机数也是相同的 System.out.println(random1.nextInt()); //264638938 System.out.println(random1.nextInt()); //172531208 }
标签:Random,System,println,Date,new,Math,out From: https://www.cnblogs.com/oyww-2027/p/17554025.html