当前位置: 首页 > 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://wiki.neutronadmin.com/news/374884/

相关文章:

  • 如何快速推广网站WordPress怎么编制手机页面
  • 龙岗网站设计案例如何做旅游网站推销
  • 寻找郑州网站建设公司wordpress视频教程下载地址
  • 注册了域名怎么做网站制作图片库
  • 手机软件下载网站推荐小白的博客 wordpress
  • wordpress 3.9 漏洞企业网站为什么做优化
  • 提供做网站公司php网站说明
  • 盐城网站建设渠道合作如何创建电商平台
  • 公司网站开发与维护活动页面设计模板
  • 网盘网站建设免费seo网站优化
  • 国家查企业的网站关键词搜索引擎又称为
  • 五金网站方案微盟小程序是什么
  • 嘉兴app开发公司专业排名优化公司
  • 做微信推送用什么网站网站收费板块怎么做
  • 怎么用微信做网站jsp做网站下载图片
  • 房地产网站建设公司东莞企业网站哪家强
  • 宝坻手机网站建设做html网站搜索框代码
  • 建设官方网站首页网站建设记入什么科目
  • 深圳推广服务兰州关键词优化排名
  • 中学网站建设工作实施方案.net 大型网站开发
  • 搜索网站青岛网站建设搭建
  • 网站建设与管理升学就业方向厦门定制网站建设
  • 手机网站分页网站开发项目分析模板
  • 山河建设有限公司网站网站单个页面做301
  • 成都建网站成都建网站商标设计创意
  • 微信网站建设公司费用北京自考网址
  • 设计本官方网站案例中国机械网招聘信息
  • 濮阳seo网站建设图书馆门户网站建设方案
  • 兰州网站运营上海网站注销
  • 网站cms系统 开源企业信息公示系统 全国