当前位置: 首页 > news >正文

下载 做网站的原型文件网站安装php

下载 做网站的原型文件,网站安装php,做网站知名的学习网站,深圳市做网站的有那些公司内容 JDK7时间相关类JDK8时间相关类 第一章 Date类 1.1 Date概述 java.util.Date类 表示特定的瞬间#xff0c;精确到毫秒。 继续查阅Date类的描述#xff0c;发现Date拥有多个构造函数#xff0c;只是部分已经过时#xff0c;我们重点看以下两个构造函数 public Dat…内容 JDK7时间相关类JDK8时间相关类 第一章 Date类 1.1 Date概述 java.util.Date类 表示特定的瞬间精确到毫秒。 继续查阅Date类的描述发现Date拥有多个构造函数只是部分已经过时我们重点看以下两个构造函数 public Date()从运行程序的此时此刻到时间原点经历的毫秒值,转换成Date对象分配Date对象并初始化此对象以表示分配它的时间精确到毫秒。public Date(long date)将指定参数的毫秒值date,转换成Date对象分配Date对象并初始化此对象以表示自从标准基准时间称为“历元epoch”即1970年1月1日00:00:00 GMT以来的指定毫秒数。 tips: 由于中国处于东八区GMT08:00是比世界协调时间/格林尼治时间GMT快8小时的时区当格林尼治标准时间为0:00时东八区的标准时间为08:00。 时间戳是一个数字定义为格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。注意同一时刻不同时区获得的时间戳是相同的。以前很多用来记录时间的字段在数据库中往往不会存储为Datetime类型而是直接存储为无符号整形存放时间戳的值。 简单来说使用无参构造可以自动设置当前系统时间的毫秒时刻指定long类型的构造参数可以自定义毫秒时刻。例如 import java.util.Date;public class Demo01Date {public static void main(String[] args) {// 创建日期对象把当前的时间System.out.println(new Date()); // Tue Jan 16 14:37:35 CST 2020// 创建日期对象把当前的毫秒值转成日期对象System.out.println(new Date(0L)); // Thu Jan 01 08:00:00 CST 1970} }tips:在使用println方法时会自动调用Date类中的toString方法。Date类对Object类中的toString方法进行了覆盖重写所以结果为指定格式的字符串。 1.2 Date常用方法 Date类中的多数方法已经过时常用的方法有 public long getTime() 把日期对象转换成对应的时间毫秒值。public void setTime(long time) 把方法参数给定的毫秒值设置给日期对象 示例代码 public class DateDemo02 {public static void main(String[] args) {//创建日期对象Date d new Date();//public long getTime():获取的是日期对象从1970年1月1日 00:00:00到现在的毫秒值//System.out.println(d.getTime());//System.out.println(d.getTime() * 1.0 / 1000 / 60 / 60 / 24 / 365 年);//public void setTime(long time):设置时间给的是毫秒值//long time 1000*60*60;long time System.currentTimeMillis();d.setTime(time);System.out.println(d);} }小结Date表示特定的时间瞬间我们可以使用Date对象对时间进行操作。 第二章 SimpleDateFormat类 java.text.SimpleDateFormat 是日期/时间格式化类我们通过这个类可以帮我们完成日期和文本之间的转换,也就是可以在Date对象与String对象之间进行来回转换。 格式化按照指定的格式把Date对象转换为String对象。解析按照指定的格式把String对象转换为Date对象。 2.1 构造方法 由于DateFormat为抽象类不能直接使用所以需要常用的子类java.text.SimpleDateFormat。这个类需要一个模式格式来指定格式化或解析的标准。构造方法为 public SimpleDateFormat(String pattern)用给定的模式和默认语言环境的日期格式符号构造SimpleDateFormat。参数pattern是一个字符串代表日期时间的自定义格式。 2.2 格式规则 常用的格式规则为 标识字母区分大小写含义y年M月d日H时m分s秒 备注更详细的格式规则可以参考SimpleDateFormat类的API文档。 2.3 常用方法 DateFormat类的常用方法有 public String format(Date date)将Date对象格式化为字符串。 public Date parse(String source)将字符串解析为Date对象。 package com.itheima.a01jdk7datedemo;import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date;public class A03_SimpleDateFormatDemo1 {public static void main(String[] args) throws ParseException {/*public simpleDateFormat() 默认格式public simpleDateFormat(String pattern) 指定格式public final string format(Date date) 格式化(日期对象 -字符串)public Date parse(string source) 解析(字符串 -日期对象)*///1.定义一个字符串表示时间String str 2023-11-11 11:11:11;//2.利用空参构造创建simpleDateFormat对象// 细节://创建对象的格式要跟字符串的格式完全一致SimpleDateFormat sdf new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);Date date sdf.parse(str);//3.打印结果System.out.println(date.getTime());//1699672271000}private static void method1() {//1.利用空参构造创建simpleDateFormat对象默认格式SimpleDateFormat sdf1 new SimpleDateFormat();Date d1 new Date(0L);String str1 sdf1.format(d1);System.out.println(str1);//1970/1/1 上午8:00//2.利用带参构造创建simpleDateFormat对象指定格式SimpleDateFormat sdf2 new SimpleDateFormat(yyyy年MM月dd日HH:mm:ss);String str2 sdf2.format(d1);System.out.println(str2);//1970年01月01日 08:00:00//课堂练习:yyyy年MM月dd日 时:分:秒 星期} } 小结DateFormat可以将Date对象和字符串相互转换。 2.4 练习1(初恋女友的出生日期) /*假设你初恋的出生年月日为:2000-11-11请用字符串表示这个数据并将其转换为:2000年11月11日创建一个Date对象表示2000年11月11日创建一个SimpleDateFormat对象并定义格式为年月日把时间变成:2000年11月11日 *///1.可以通过2000-11-11进行解析解析成一个Date对象 String str 2000-11-11; //2.解析 SimpleDateFormat sdf1 new SimpleDateFormat(yyyy-MM-dd); Date date sdf1.parse(str); //3.格式化 SimpleDateFormat sdf2 new SimpleDateFormat(yyyy年MM月dd日); String result sdf2.format(date); System.out.println(result);2.5 练习2(秒杀活动) /* 需求:秒杀活动开始时间:2023年11月11日 0:0:0(毫秒值)秒杀活动结束时间:2023年11月11日 0:10:0(毫秒值)小贾下单并付款的时间为:2023年11月11日 0:01:0小皮下单并付款的时间为:2023年11月11日 0:11:0用代码说明这两位同学有没有参加上秒杀活动?*///1.定义字符串表示三个时间 String startstr 2023年11月11日 0:0:0; String endstr 2023年11月11日 0:10:0; String orderstr 2023年11月11日 0:01:00; //2.解析上面的三个时间得到Date对象 SimpleDateFormat sdf new SimpleDateFormat(yyyy年MM月dd日HH:mm:ss); Date startDate sdf.parse(startstr); Date endDate sdf.parse(endstr); Date orderDate sdf.parse(orderstr);//3.得到三个时间的毫秒值 long startTime startDate.getTime(); long endTime endDate.getTime(); long orderTime orderDate.getTime();//4.判断 if (orderTime startTime orderTime endTime) {System.out.println(参加秒杀活动成功); } else {System.out.println(参加秒杀活动失败); }第三章 Calendar类 3.1 概述 java.util.Calendar类表示一个“日历类”可以进行日期运算。它是一个抽象类不能创建对象我们可以使用它的子类java.util.GregorianCalendar类。有两种方式可以获取GregorianCalendar对象 直接创建GregorianCalendar对象通过Calendar的静态方法getInstance()方法获取GregorianCalendar对象【本次课使用】 3.2 常用方法 方法名说明public static Calendar getInstance()获取一个它的子类GregorianCalendar对象。public int get(int field)获取某个字段的值。field参数表示获取哪个字段的值可以使用Calender中定义的常量来表示Calendar.YEAR : 年Calendar.MONTH 月Calendar.DAY_OF_MONTH月中的日期Calendar.HOUR小时Calendar.MINUTE分钟Calendar.SECOND秒Calendar.DAY_OF_WEEK星期public void set(int field,int value)设置某个字段的值public void add(int field,int amount)为某个字段增加/减少指定的值 3.3 get方法示例 public class Demo {public static void main(String[] args) {//1.获取一个GregorianCalendar对象Calendar instance Calendar.getInstance();//获取子类对象//2.打印子类对象System.out.println(instance);//3.获取属性int year instance.get(Calendar.YEAR);int month instance.get(Calendar.MONTH) 1;//Calendar的月份值是0-11int day instance.get(Calendar.DAY_OF_MONTH);int hour instance.get(Calendar.HOUR);int minute instance.get(Calendar.MINUTE);int second instance.get(Calendar.SECOND);int week instance.get(Calendar.DAY_OF_WEEK);//返回值范围1--7分别表示星期日,星期一,星期二,...,星期六System.out.println(year 年 month 月 day 日 hour : minute : second);System.out.println(getWeek(week));}//查表法查询星期几public static String getWeek(int w) {//w 1 --- 7//做一个表(数组)String[] weekArray {星期日, 星期一, 星期二, 星期三, 星期四, 星期五, 星期六};// 索引 [0] [1] [2] [3] [4] [5] [6]//查表return weekArray[w - 1];} } 3.4 set方法示例 public class Demo {public static void main(String[] args) {//设置属性——set(int field,int value):Calendar c1 Calendar.getInstance();//获取当前日期//计算班长出生那天是星期几(假如班长出生日期为1998年3月18日)c1.set(Calendar.YEAR, 1998);c1.set(Calendar.MONTH, 3 - 1);//转换为Calendar内部的月份值c1.set(Calendar.DAY_OF_MONTH, 18);int w c1.get(Calendar.DAY_OF_WEEK);System.out.println(班长出生那天是 getWeek(w));}//查表法查询星期几public static String getWeek(int w) {//w 1 --- 7//做一个表(数组)String[] weekArray {星期日, 星期一, 星期二, 星期三, 星期四, 星期五, 星期六};// 索引 [0] [1] [2] [3] [4] [5] [6]//查表return weekArray[w - 1];} }3.5 add方法示例 public class Demo {public static void main(String[] args) {//计算200天以后是哪年哪月哪日星期几Calendar c2 Calendar.getInstance();//获取当前日期c2.add(Calendar.DAY_OF_MONTH, 200);//日期加200int y c2.get(Calendar.YEAR);int m c2.get(Calendar.MONTH) 1;//转换为实际的月份int d c2.get(Calendar.DAY_OF_MONTH);int wk c2.get(Calendar.DAY_OF_WEEK);System.out.println(200天后是 y 年 m 月 d 日 getWeek(wk));}//查表法查询星期几public static String getWeek(int w) {//w 1 --- 7//做一个表(数组)String[] weekArray {星期日, 星期一, 星期二, 星期三, 星期四, 星期五, 星期六};// 索引 [0] [1] [2] [3] [4] [5] [6]//查表return weekArray[w - 1];} }第四章 JDK8时间相关类 JDK8时间类类名作用ZoneId时区Instant时间戳ZoneDateTime带时区的时间DateTimeFormatter用于时间的格式化和解析LocalDate年、月、日LocalTime时、分、秒LocalDateTime年、月、日、时、分、秒Duration时间间隔秒纳秒Period时间间隔年月日ChronoUnit时间间隔所有单位 4.1 ZoneId 时区 /*static Setstring getAvailableZoneIds() 获取Java中支持的所有时区static ZoneId systemDefault() 获取系统默认时区static Zoneld of(string zoneld) 获取一个指定时区*///1.获取所有的时区名称 SetString zoneIds ZoneId.getAvailableZoneIds(); System.out.println(zoneIds.size());//600 System.out.println(zoneIds);// Asia/Shanghai//2.获取当前系统的默认时区 ZoneId zoneId ZoneId.systemDefault(); System.out.println(zoneId);//Asia/Shanghai//3.获取指定的时区 ZoneId zoneId1 ZoneId.of(Asia/Pontianak); System.out.println(zoneId1);//Asia/Pontianak4.2 Instant 时间戳 /*static Instant now() 获取当前时间的Instant对象(标准时间)static Instant ofXxxx(long epochMilli) 根据(秒/毫秒/纳秒)获取Instant对象ZonedDateTime atZone(ZoneIdzone) 指定时区boolean isxxx(Instant otherInstant) 判断系列的方法Instant minusXxx(long millisToSubtract) 减少时间系列的方法Instant plusXxx(long millisToSubtract) 增加时间系列的方法*/ //1.获取当前时间的Instant对象(标准时间) Instant now Instant.now(); System.out.println(now);//2.根据(秒/毫秒/纳秒)获取Instant对象 Instant instant1 Instant.ofEpochMilli(0L); System.out.println(instant1);//1970-01-01T00:00:00zInstant instant2 Instant.ofEpochSecond(1L); System.out.println(instant2);//1970-01-01T00:00:01ZInstant instant3 Instant.ofEpochSecond(1L, 1000000000L); System.out.println(instant3);//1970-01-01T00:00:027//3. 指定时区 ZonedDateTime time Instant.now().atZone(ZoneId.of(Asia/Shanghai)); System.out.println(time);//4.isXxx 判断 Instant instant4Instant.ofEpochMilli(0L); Instant instant5 Instant.ofEpochMilli(1000L);//5.用于时间的判断 //isBefore:判断调用者代表的时间是否在参数表示时间的前面 boolean result1instant4.isBefore(instant5); System.out.println(result1);//true//isAfter:判断调用者代表的时间是否在参数表示时间的后面 boolean result2 instant4.isAfter(instant5); System.out.println(result2);//false//6.Instant minusXxx(long millisToSubtract) 减少时间系列的方法 Instant instant6 Instant.ofEpochMilli(3000L); System.out.println(instant6);//1970-01-01T00:00:03ZInstant instant7 instant6.minusSeconds(1); System.out.println(instant7);//1970-01-01T00:00:02Z 4.3 ZoneDateTime 带时区的时间 /*static ZonedDateTime now() 获取当前时间的ZonedDateTime对象static ZonedDateTime ofXxxx(。。。) 获取指定时间的ZonedDateTime对象ZonedDateTime withXxx(时间) 修改时间系列的方法ZonedDateTime minusXxx(时间) 减少时间系列的方法ZonedDateTime plusXxx(时间) 增加时间系列的方法*/ //1.获取当前时间对象(带时区) ZonedDateTime now ZonedDateTime.now(); System.out.println(now);//2.获取指定的时间对象(带时区)1/年月日时分秒纳秒方式指定 ZonedDateTime time1 ZonedDateTime.of(2023, 10, 1,11, 12, 12, 0, ZoneId.of(Asia/Shanghai)); System.out.println(time1);//通过Instant 时区的方式指定获取时间对象 Instant instant Instant.ofEpochMilli(0L); ZoneId zoneId ZoneId.of(Asia/Shanghai); ZonedDateTime time2 ZonedDateTime.ofInstant(instant, zoneId); System.out.println(time2);//3.withXxx 修改时间系列的方法 ZonedDateTime time3 time2.withYear(2000); System.out.println(time3);//4. 减少时间 ZonedDateTime time4 time3.minusYears(1); System.out.println(time4);//5.增加时间 ZonedDateTime time5 time4.plusYears(1); System.out.println(time5);4.4DateTimeFormatter 用于时间的格式化和解析 /*static DateTimeFormatter ofPattern(格式) 获取格式对象String format(时间对象) 按照指定方式格式化*/ //获取时间对象 ZonedDateTime time Instant.now().atZone(ZoneId.of(Asia/Shanghai));// 解析/格式化器 DateTimeFormatter dtf1DateTimeFormatter.ofPattern(yyyy-MM-dd HH:mm;ss EE a); // 格式化 System.out.println(dtf1.format(time));4.5LocalDate 年、月、日 //1.获取当前时间的日历对象(包含 年月日) LocalDate nowDate LocalDate.now(); //System.out.println(今天的日期: nowDate); //2.获取指定的时间的日历对象 LocalDate ldDate LocalDate.of(2023, 1, 1); System.out.println(指定日期: ldDate);System.out.println();//3.get系列方法获取日历中的每一个属性值//获取年 int year ldDate.getYear(); System.out.println(year: year); //获取月//方式一: Month m ldDate.getMonth(); System.out.println(m); System.out.println(m.getValue());//方式二: int month ldDate.getMonthValue(); System.out.println(month: month);//获取日 int day ldDate.getDayOfMonth(); System.out.println(day: day);//获取一年的第几天 int dayofYear ldDate.getDayOfYear(); System.out.println(dayOfYear: dayofYear);//获取星期 DayOfWeek dayOfWeek ldDate.getDayOfWeek(); System.out.println(dayOfWeek); System.out.println(dayOfWeek.getValue());//is开头的方法表示判断 System.out.println(ldDate.isBefore(ldDate)); System.out.println(ldDate.isAfter(ldDate));//with开头的方法表示修改只能修改年月日 LocalDate withLocalDate ldDate.withYear(2000); System.out.println(withLocalDate);//minus开头的方法表示减少只能减少年月日 LocalDate minusLocalDate ldDate.minusYears(1); System.out.println(minusLocalDate);//plus开头的方法表示增加只能增加年月日 LocalDate plusLocalDate ldDate.plusDays(1); System.out.println(plusLocalDate);//------------- // 判断今天是否是你的生日 LocalDate birDate LocalDate.of(2000, 1, 1); LocalDate nowDate1 LocalDate.now();MonthDay birMd MonthDay.of(birDate.getMonthValue(), birDate.getDayOfMonth()); MonthDay nowMd MonthDay.from(nowDate1);System.out.println(今天是你的生日吗? birMd.equals(nowMd));//今天是你的生日吗?4.6 LocalTime 时、分、秒 // 获取本地时间的日历对象。(包含 时分秒) LocalTime nowTime LocalTime.now(); System.out.println(今天的时间: nowTime);int hour nowTime.getHour();//时 System.out.println(hour: hour);int minute nowTime.getMinute();//分 System.out.println(minute: minute);int second nowTime.getSecond();//秒 System.out.println(second: second);int nano nowTime.getNano();//纳秒 System.out.println(nano: nano); System.out.println(------------------------------------); System.out.println(LocalTime.of(8, 20));//时分 System.out.println(LocalTime.of(8, 20, 30));//时分秒 System.out.println(LocalTime.of(8, 20, 30, 150));//时分秒纳秒 LocalTime mTime LocalTime.of(8, 20, 30, 150);//is系列的方法 System.out.println(nowTime.isBefore(mTime)); System.out.println(nowTime.isAfter(mTime));//with系列的方法只能修改时、分、秒 System.out.println(nowTime.withHour(10));//plus系列的方法只能修改时、分、秒 System.out.println(nowTime.plusHours(10));4.7 LocalDateTime 年、月、日、时、分、秒 // 当前时间的的日历对象(包含年月日时分秒) LocalDateTime nowDateTime LocalDateTime.now();System.out.println(今天是: nowDateTime);//今天是 System.out.println(nowDateTime.getYear());//年 System.out.println(nowDateTime.getMonthValue());//月 System.out.println(nowDateTime.getDayOfMonth());//日 System.out.println(nowDateTime.getHour());//时 System.out.println(nowDateTime.getMinute());//分 System.out.println(nowDateTime.getSecond());//秒 System.out.println(nowDateTime.getNano());//纳秒 // 日:当年的第几天 System.out.println(dayofYear: nowDateTime.getDayOfYear()); //星期 System.out.println(nowDateTime.getDayOfWeek()); System.out.println(nowDateTime.getDayOfWeek().getValue()); //月份 System.out.println(nowDateTime.getMonth()); System.out.println(nowDateTime.getMonth().getValue());LocalDate ld nowDateTime.toLocalDate(); System.out.println(ld);LocalTime lt nowDateTime.toLocalTime(); System.out.println(lt.getHour()); System.out.println(lt.getMinute()); System.out.println(lt.getSecond());4.8 Duration 时间间隔秒纳秒 // 本地日期时间对象。 LocalDateTime today LocalDateTime.now(); System.out.println(today);// 出生的日期时间对象 LocalDateTime birthDate LocalDateTime.of(2000, 1, 1, 0, 0, 0); System.out.println(birthDate);Duration duration Duration.between(birthDate, today);//第二个参数减第一个参数 System.out.println(相差的时间间隔对象: duration);System.out.println(); System.out.println(duration.toDays());//两个时间差的天数 System.out.println(duration.toHours());//两个时间差的小时数 System.out.println(duration.toMinutes());//两个时间差的分钟数 System.out.println(duration.toMillis());//两个时间差的毫秒数 System.out.println(duration.toNanos());//两个时间差的纳秒数4.9 Period 时间间隔年月日 // 当前本地 年月日 LocalDate today LocalDate.now(); System.out.println(today);// 生日的 年月日 LocalDate birthDate LocalDate.of(2000, 1, 1); System.out.println(birthDate);Period period Period.between(birthDate, today);//第二个参数减第一个参数System.out.println(相差的时间间隔对象: period); System.out.println(period.getYears()); System.out.println(period.getMonths()); System.out.println(period.getDays());System.out.println(period.toTotalMonths());4.10 ChronoUnit 时间间隔所有单位 // 当前时间 LocalDateTime today LocalDateTime.now(); System.out.println(today); // 生日时间 LocalDateTime birthDate LocalDateTime.of(2000, 1, 1,0, 0, 0); System.out.println(birthDate);System.out.println(相差的年数: ChronoUnit.YEARS.between(birthDate, today)); System.out.println(相差的月数: ChronoUnit.MONTHS.between(birthDate, today)); System.out.println(相差的周数: ChronoUnit.WEEKS.between(birthDate, today)); System.out.println(相差的天数: ChronoUnit.DAYS.between(birthDate, today)); System.out.println(相差的时数: ChronoUnit.HOURS.between(birthDate, today)); System.out.println(相差的分数: ChronoUnit.MINUTES.between(birthDate, today)); System.out.println(相差的秒数: ChronoUnit.SECONDS.between(birthDate, today)); System.out.println(相差的毫秒数: ChronoUnit.MILLIS.between(birthDate, today)); System.out.println(相差的微秒数: ChronoUnit.MICROS.between(birthDate, today)); System.out.println(相差的纳秒数: ChronoUnit.NANOS.between(birthDate, today)); System.out.println(相差的半天数: ChronoUnit.HALF_DAYS.between(birthDate, today)); System.out.println(相差的十年数: ChronoUnit.DECADES.between(birthDate, today)); System.out.println(相差的世纪(百年)数: ChronoUnit.CENTURIES.between(birthDate, today)); System.out.println(相差的千年数: ChronoUnit.MILLENNIA.between(birthDate, today)); System.out.println(相差的纪元数: ChronoUnit.ERAS.between(birthDate, today));
http://www.pierceye.com/news/888136/

相关文章:

  • 网站推广广告 优帮云开发公司资质哪里查
  • 沈阳网站建设思路做海报的话网站
  • 扬州网站建设suteng崇左网页设计
  • 中文网站模板html做网站 最好的开源cms
  • 个人资料展示网站网站建设网络推广外包服务商
  • 外贸网站建设有什么需要注意的吗网站建设职业发展前景
  • 企业网站建设方案效果版权WordPress
  • 做网站知道访客ip汝州文明建设网站
  • 吴江建设局网站打不开了网站备案信息地址
  • 长沙网站建设优化局域网网站架设软件
  • 重庆企业网站建设解决方案seo关键词怎么优化
  • 信誉好的大良网站建设做的好的ppt下载网站有哪些
  • 栖霞网站定制手机网站图片自适应代码
  • 企业网站管理中心网站海外推广
  • 书店商城网站设计万网虚拟主机做网站教程
  • 文化类网站是不是休闲娱乐类网站wordpress插件 ftp
  • 织梦系统网站吉林省建设安全厅官方网站
  • 网站推广网站关键词排名怎么做建站教程wp
  • 用织梦系统做网站产权网站建设需要掌握什么技术
  • 南宁seo平台费用安徽网站关键词优化排名
  • 李贤威 wordpress甘肃搜索引擎网络优化
  • 网站建设的步骤图片过程9377将军
  • 做彩票网站需要什么服务器wordpress slug
  • 个人空间网站建设太原做网页软件
  • 网站建站方式有哪些wordpress星座主题自适应
  • 如何为公司做网站算命 网站开发
  • 那些做软件的网站十大装潢公司上海
  • wordpress 仿站 主题公路建设网站
  • 接网站 建设网站建设业务员招聘
  • 江西工程建设信息网站服装公司网站建设