JavaJoop08实用类

枚举类

 public enum Student {
     name,sex,age;
 }

包装类

byte–>Byte

short–>Short

int–>Integer

long–>Long

float–>Float

double–>Double

char–>Character

boolean–>Boolean

自动装箱:把基本数据类型变量直接转换为对应的包装类对象,或者转换为object对象
 int   a=10;
 Integer  a1=new Integer(a);
自动拆箱:与装箱相反,将包装类对象转换成对应的基本数据类型的变量
 Integer a1=new Integer (10);
 int a=a1;

日期类

//获取当前日期


        //获得当前日期在一周,一月,一年中的第几天
       LocalDate date=LocalDate.now();
        System.out.println("当前日期"+date);
        LocalTime time=LocalTime.now();
        System.out.println("当前时间"+time);
        LocalDateTime dateTime=LocalDateTime.now();
        System.out.println("当前日期和时间"+dateTime);

获取当前日期的月份,年份
        System.out.println(date.getMonth());
        System.out.println(date.getYear());
获取当前日期的月份的int值
        Month month=date.getMonth() ;
        System.out.println(date.getMonthValue());

        //当前日期增加天数,周数,月数,年数
        System.out.println(date.plusDays(2));
        System.out.println(date.plusWeeks(4));
        System.out.println(date.plusMonths(4));
        System.out.println(date.plusYears(8));

//格式化的两种方式
 ​
 //简单的日期格式化
 ​
        SimpleDateFormat format=new SimpleDateFormat("YYYY年MM月dd日");
       System.out.println(format.format(new Date()));
 标准的格式化方法
       LocalDate date=LocalDate.now();
       DateTimeFormatter formatter=DateTimeFormatter.ofPattern("YYYY年MM月dd日");                  System.out.println(formatter.format(date));
//获取系统毫秒
 //      
         System.out.println(System.currentTimeMillis());
         Thread.sleep(1000);
         System.out.println(System.currentTimeMillis());请输入你今年的生日:(YYYY—MM-DD)
 ​
获取一些关于生日的日期

System.out.println("请输入你今年的生日:(YYYY—MM-DD)");
String birthdy= input.next();
String[] split = birthdy.split("-");
int year=Integer.parseInt(split[0]);
int month=Integer.parseInt(split[1]);
int day=Integer.parseInt(split[2]);
LocalDate date=LocalDate.of(year,month,day);
LocalDate localDate=LocalDate.now();
System.out.println("今天日期:"+localDate);
System.out.println("今年的生日:"+date);
System.out.println("在一年中的天数:"+date.getDayOfYear());
System.out.println("在当月中的天数:"+date.getDayOfMonth());
System.out.println("星期:"+date.getDayOfWeek());

请输入你今年的生日:(YYYY—MM-DD)
2023-05-05
今天日期:2023-08-17
今年的生日:2023-05-05
在一年中的天数:125
在当月中的天数:5
星期:FRIDAY

随机类

//随机数
 ​
         Random random=new Random();
         Random random1=new Random();
         System.out.println(random.nextInt());
         System.out.println(random1.nextInt());
随机一个验证码:

数字:

         Random random=new Random();
         String num="";
         for (int i = 0; i <5 ; i++) {
             num+=random.nextInt(5)+" ";
         }
         System.out.println("获取5位全是数字验证码"+num);

字母:

Random random=new Random();
 String zz="";
String [] zhiMus={"Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M"};
        for (int i = 0; i <5 ; i++) {
           zz+=zhiMus[random.nextInt(26)]+" ";

        }
        System.out.println("获取5位验证码(大写字母)"+zz);

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值