ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

2022-07-28 第七小组 房雪莹 学习笔记

2022-07-28 20:02:43  阅读:183  来源: 互联网

标签:07 28 System 2022 println Calendar now calendar out


今日学习内容:

1.java的值传递和所谓的引用传递
本质上Java只有值传递,所有的赋值传参都是一次值得拷贝
引用数据类型拷贝的就是引用地址,基本数据类型拷贝的是值,不会传入实例

2.常用API(Application Programming Interface)应用程序接口
JDK给我们提供的一些已经写好的类,可以直接调方法解决问题
String
我们类的方法在宏观上就可以称为接口

3.日期类(Date)

Date date=new Date();
System.out.println(date);

4.

 Date date1=new Date(1658974415756L);//10:13
        Date date2=new Date();
//        System.out.println(date2.after(date1));

        /**
         * 当返回负数时,说明调用者时间是在参数时间之前
         * 当返回0时,调用者时间和参数时间相同
         * 当返回正数时,说明调用者时间是在参数时间之后
         */
        System.out.println(date1.compareTo(date2));

5.日历类:日期

Calendar calendar =Calendar.getInstance();
    System.out.println(calendar.get(Calendar.YEAR));
    System.out.println(calendar.get(Calendar.DAY_OF_YEAR));
    System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
    System.out.println(calendar.get(Calendar.MONTH));
    System.out.println(calendar.get(Calendar.HOUR));
    System.out.println(calendar.get(Calendar.HOUR_OF_DAY));
    System.out.println(calendar.get(Calendar.MILLISECOND));

 6.时区:

System.out.println(TimeZone.getDefault());
Calendar calendar=Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone("GMT-8:00"));

7.ZoneId

ZoneId zoneId=ZoneId.of("America /New_York");
System.out.println(TimeZone.getTimeZone(zoneId));

 8.日期格式化:

SimpleDateFormat

 

Date date=new Date();
System.out.println(date);
/**
 * yyyy:代表年
 * yy:年的后两位
 * MM:月
 * dd:日
 * HH:小时24小时制
 * hh:小时12小时制
 * mm:分
 * ss:秒
 * SSS:毫秒
 */
SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日");
String s = sdf.format(date);
System.out.println(s);

 9.

Instant instant=Instant.now();
System.out.println(instant.atZone(ZoneId.systemDefault()));

//获取纪元秒数
System.out.println(instant.getEpochSecond());
//获取毫秒数
System.out.println(instant.toEpochMilli());
long millis=System.currentTimeMillis();
System.out.println(Instant.ofEpochMilli(millis));
System.out.println("--------------------------------------");
String text="2022-07-28T14:06:50.174Z";
Instant parse=Instant.parse(text);
System.out.println(parse);

 10.持续时间:

Instant instant=Instant.now();
Instant plus = instant.plus(Duration.ofDays(5));
System.out.println(plus);

 11.

 LocalDate:获取当前日期

 

 LocalDate now=LocalDate.now();
 System.out.println(now);
 System.out.println(now.getMonth());
 System.out.println(now.getDayOfWeek());
 System.out.println(now.getDayOfMonth());
LocalDate of = LocalDate.of(2024, 5, 6);
 System.out.println(of);

 //判断是否为闰年
 // 能被4整除不被100,被400整除
 System.out.println(of.isLeapYear());

 12.

LocalTime获取本地时间

 

LocalTime now=LocalTime.now();
System.out.println(now);

 13.

 LocalDateTime:获取日期和时间

 

System.out.println(LocalDateTime.now());

 14.

DateTimeFormatter处理日期格式化问题
LocalDate now=LocalDate.now();
DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern("yyyy/MM/dd");
System.out.println(now.format(dateTimeFormatter));

15.

BigDecimal统计类
BigDecimal bigDecimal1=new BigDecimal("0.7");
BigDecimal bigDecimal2=new BigDecimal("0.1");
System.out.println(bigDecimal1.add(bigDecimal2));

16.

随机
* Random
Random random=new Random();
System.out.println(random.nextInt(2));

17.

Arrays数组工具类
int []arr=new int[]{1,2,3,4,5,6};
System.out.println(Arrays.toString(arr));
Arrays.sort(arr);
System.out.println(Arrays.binarySearch(arr,4));
int [] ints=Arrays.copyOf(arr,2);
System.out.println(Arrays.toString(ints));
System.out.println(Arrays.equals(arr, ints));

 18.

 System类
* 系统类

 

Properties properties = System.getProperties();
System.out.println(properties);

 19.

Objects

 

System.out.println(Objects.isNull(""));

 20.

StringBuffer和StringBuilder
* 可变的字符序列,和String是有本质区别的
*
*  String怎么反转???
*
*  StringBuffer是同步的。安全,效率低
*  StringBuilder是异步的。不安全。效率高

 

 StringBuffer stringBuffer = new StringBuffer("你好");
//        System.out.println(stringBuffer);
        stringBuffer.append(",我好").append(",大家好");
//        System.out.println(stringBuffer);

//        stringBuffer.delete(4,7);
//        stringBuffer.deleteCharAt(0);
//        stringBuffer.insert(1,"哈哈");
        stringBuffer.reverse();
        System.out.println(stringBuffer);
//        String str = "hello";
//        String s = str.concat(",world!!");
//        System.out.println("str = " + str);
//        System.out.println("s = " + s);
    }

 

标签:07,28,System,2022,println,Calendar,now,calendar,out
来源: https://www.cnblogs.com/fxy1003/p/16530027.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有