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

微页制作网站模板下载网站的优化外包

微页制作网站模板下载,网站的优化外包,深圳做网站排名公司,网站开发设计软件Jdk1.8之时间处理该文章已经同步到Github#xff1a;https://github.com/stackInk/makerstack1. 传统时间处理的问题1.1 多线程环境下的SimpleDateFormat当多个线程使用同一个时间处理对象进行对日期的格式化的时候#xff0c;会出现java.lang.NumberFormatException: multip…Jdk1.8之时间处理该文章已经同步到Githubhttps://github.com/stackInk/makerstack1. 传统时间处理的问题1.1 多线程环境下的SimpleDateFormat当多个线程使用同一个时间处理对象进行对日期的格式化的时候会出现java.lang.NumberFormatException: multiple points。主要原因是由于SimpleDateFormat是线程不安全的当线程共享的时候会引发这个异常。1.1.1 代码演示SimpleDateFormat simpleDateFormat new SimpleDateFormat(yyyyMMdd); //线程池中线程共享了SimpleDateFormat引发线程不安全 CallableString callable () - simpleDateFormat.parse(20200402).toString();ExecutorService executorService Executors.newFixedThreadPool(10); ListFutureString list new LinkedList();for (int i 0; i 10; i) {FutureString submit executorService.submit(callable);list.add(submit); } for (FutureString stringFuture : list) {String s stringFuture.get();System.out.println(s); } executorService.shutdown(); 解决方法线程不共享变量SimpleDateFormat每一个线程在进行日期格式化的时候都自己创建一个ExecutorService executorService Executors.newFixedThreadPool(10); ListFutureString list new LinkedList(); for (int i 0; i 10; i) {FutureString submit executorService.submit(new MyCallable01(20200403));list.add(submit); } for (FutureString stringFuture : list) {String s stringFuture.get();System.out.println(s);} executorService.shutdown();class MyCallable01 implements CallableString{private String date ;public MyCallable01(String date) {this.date date;}Overridepublic String call() throws Exception {SimpleDateFormat simpleDateFormat new SimpleDateFormat(yyyyMMdd);return simpleDateFormat.parse(date).toString();} } 通过ThreadLocal为每一个线程绑定一个SimpleDateFormateFutureString submit executorService.submit(() - ResolveByThreadLocal.converDateStrToDate(20200405));public class ResolveByThreadLocal {//创建一个绑定每一个变量的ThreadLocalprivate static final ThreadLocalSimpleDateFormat threadLocal new ThreadLocal();public static String converDateStrToDate(String date) throws ParseException {SimpleDateFormat simpleDateFormat threadLocal.get(); ;if(simpleDateFormat null){simpleDateFormat new SimpleDateFormat(yyyyMMdd);threadLocal.set(simpleDateFormat);}Date parse simpleDateFormat.parse(date);return parse.toString() ;} }2. 1.8时间处理对于时间的处理均在java.time包及其子包中且线程安全java.time包下存放了进行时间处理的各种类 Instant获取本地时间的时间戳LocalDate获取本地时间的日期LocalTime获取本地时间的时间LocalDateTime获取本地时间的日期和时间Duration计算两个日期之间的间隔Period计算两个时间的间隔OffsetDateTime对日期和时间进行偏移量计算offsetTime对时间进行偏移量计算ZoneId各种时区代码ZoneOffset市区偏移量计算ZonedDateTimejava.time.chrono不同地区时间记时方式java.time.temporal对时间进行一些调整的包java.time.format对时间进行格式化2.1 LocalDate、LocalTime、LocalDateTime三者的使用方式完全相同输出的结果不同now获取本地时间LocalDateTime now LocalDateTime.now();System.out.println(now);System.out.println(now.getYear());System.out.println(now.getMonthValue());//直接获取月份的值System.out.println(now.getDayOfMonth());System.out.println(now.getHour());System.out.println(now.getMinute());System.out.println(now.getSecond());输出: 2020-04-03T10:25:29.906 2020 4 3 10 25 29 of()传入指定的日期和时间对时间进行偏移量加计算对事件进行偏移量减运算当前时间与另一个时间的比较将月份天数年份天数月份等修改为指定的值返回一个新的LocalDateTime对象get方法format(DateTimeFormatter formatter)对日期进行格式化until返回两个日期之间的Period对象isLeapYear判断是否为闰年2.2 Instant时间戳以Unix元年(传统设定为UTC时区1970年1月1日)开始所经历的描述进行运算获取当前时间的时间戳toEpochMilli获取当前时间的秒getEpochSecond对时间进行偏移Instant.now().ofHours(ZoneOffset.ofHours(int hours))2.3 TemporalAdjuster 时间校正器主要通过TemporalAdjusters工具类获取到TemporalAdjuster实例对象LocalDateTime now LocalDateTime.now();//直接调用JDK提供的时间校正器LocalDateTime with now.with(TemporalAdjusters.next(DayOfWeek.SUNDAY));System.out.println(with);//自定义一个时间校正器计算下一个工作日LocalDateTime with2 now.with(e - {LocalDateTime e1 (LocalDateTime) e;DayOfWeek dayOfWeek e1.getDayOfWeek();if (dayOfWeek.equals(DayOfWeek.FRIDAY)) {return e1.plusDays(3);} else if (dayOfWeek.equals(DayOfWeek.SATURDAY)) {return e1.plusDays(2);} else {return e1.plusDays(1);}});System.out.println(with2); 2.4 DateTimeFormatter日期格式化三种格式化方法预定义的标准格式语言环境相关的格式自定义的格式2.4.1 预定义的标准格式JDK提供的格式化格式LocalDate localDate LocalDate.now(); String format localDate.format(DateTimeFormatter.ISO_DATE); 输出2020-04-03 2.4.1 自定义的时间格式//自定义日期格式化方式可以通过format和parse对日期进行格式化 DateTimeFormatter dateTimeFormatter DateTimeFormatter.ofPattern(yyyy年MM月dd日); String format1 localDate.format(dateTimeFormatter); System.out.println(format1); localDate.parse(format1,dateTimeFormatter);输出2020年04月03日2020-04-03 2.5 时区处理2.5.1 ZoneId获取所有的时区信息 SetString availableZoneIds ZoneId.getAvailableZoneIds(); 获取指定时区信息的ZoneId对象ZoneId of ZoneId.of(Asia/Chungking); 2.5.2 ZonedDateTime获取一个带时区的日期时间对象ZonedDateTime now ZonedDateTime.now();System.out.println(now); //输出 2020-04-03T14:22:54.25008:00[Asia/Shanghai] 其他用法和LocalDateTime类相同7000字长文带你深入IOC加载流程​mp.weixin.qq.comSpringMVC的执行流程你想知道的都有​mp.weixin.qq.com
http://www.yutouwan.com/news/453952/

相关文章:

  • 最专业的网站建设组织地区网站建设服务周到
  • 做淘宝浏览单的网站平台公司拿地
  • 美妆网站建设环境分析网站代管理
  • 网站用什么框架做wordpress站内seo
  • 网站seo优化推广怎么做网店推广的作用是选择题
  • 网站空间 phpwordpress主题 免费 自媒体
  • iis配置网站是什么各网站封面尺寸
  • 做写字楼租赁用什么网站好wordpress页脚贴底部
  • 湘阴网站设计青海手机网站建设
  • 网站短链接生成器长沙企业模板建站
  • 电子商城平台网站开发我做的网站有时打开很慢什么原因
  • 大连 网站制作深圳做微网站
  • 河北网站建设与管理上海小程序网站开发公司
  • asp网站源码使用wordpress支持代码高亮
  • 访问网站有音乐背景怎么做做海淘的网站做海淘的网站
  • 网站开发毕设ppt电脑网站兼职在哪里做
  • 仿《快乐麻花》网站源码家居装饰网站设计论文
  • soho建网站哪有做网站的
  • 南京触屏网站开发百度地图在线使用导航系统
  • 做网站文案用哪个软件网页美工设计时色彩搭配的注意事项
  • 网站优化的怎样给公司做免费网站
  • 南昌企业网站模板建站台州路桥做网站的公司有哪些
  • 用服务器做网站需要购买域名吗北京学做网站
  • 做seo是要先有网站吗哪个网站专门做母婴
  • 济南川芎网站建设公司武邑县网站建设
  • 台州网站建设慕枫用php做购物网站
  • 加快建设企业门户网站建成都住建局官网全生命周期
  • 专做杰伦头像的网站百度网盟推广案例
  • 网站设计与建设网站备份
  • 企业怎么做网络推广泉州seo网站关键词优推广