做网站的职位叫什么问题建一个团购网站需要多少钱

news/2025/10/5 15:47:01/文章来源:
做网站的职位叫什么问题,建一个团购网站需要多少钱,建设网站分析报告,贵州网站建设公司目录 在日常开发中#xff0c;Date工具类使用频率相对较高#xff0c;大家通常都会这样写#xff1a;这很简单啊#xff0c;有什么争议吗#xff1f;格式化后出现的时间错乱。看看Java 8是如何解决时区问题的#xff1a;在处理带时区的国际化时间问题#xff0c;推荐使用… 目录 在日常开发中Date工具类使用频率相对较高大家通常都会这样写这很简单啊有什么争议吗格式化后出现的时间错乱。看看Java 8是如何解决时区问题的在处理带时区的国际化时间问题推荐使用jdk8的日期时间类在与前端联调时报了个错java.lang.NumberFormatException: multiple points起初我以为是时间格式传的不对仔细一看不对啊。看一下SimpleDateFormat.parse的源码 大家好我是哪吒。 在日常开发中Date工具类使用频率相对较高大家通常都会这样写 public static Date getData(String date) throws ParseException {SimpleDateFormat sdf new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);return sdf.parse(date); }public static Date getDataByFormat(String date, String format) throws ParseException {SimpleDateFormat sdf new SimpleDateFormat(format);return sdf.parse(date); }这很简单啊有什么争议吗 你应该听过“时区”这个名词大家也都知道相同时刻不同时区的时间是不一样的。 因此在使用时间时一定要给出时区信息。 public static void getDataByZone(String param, String format) throws ParseException {SimpleDateFormat sdf new SimpleDateFormat(format);// 默认时区解析时间表示Date date sdf.parse(param);System.out.println(date : date.getTime());// 东京时区解析时间表示sdf.setTimeZone(TimeZone.getTimeZone(Asia/Tokyo));Date newYorkDate sdf.parse(param);System.out.println(newYorkDate : newYorkDate.getTime()); }public static void main(String[] args) throws ParseException {getDataByZone(2023-11-10 10:00:00,yyyy-MM-dd HH:mm:ss); }对于当前的上海时区和纽约时区转化为 UTC 时间戳是不同的时间。 对于同一个本地时间的表示不同时区的人解析得到的 UTC 时间一定是不同的反过来不同的本地时间可能对应同一个 UTC。 格式化后出现的时间错乱。 public static void getDataByZoneFormat(String param, String format) throws ParseException {SimpleDateFormat sdf new SimpleDateFormat(format);Date date sdf.parse(param);// 默认时区格式化输出System.out.println(new SimpleDateFormat([yyyy-MM-dd HH:mm:ss Z]).format(date));// 东京时区格式化输出TimeZone.setDefault(TimeZone.getTimeZone(Asia/Tokyo));System.out.println(new SimpleDateFormat([yyyy-MM-dd HH:mm:ss Z]).format(date)); }public static void main(String[] args) throws ParseException {getDataByZoneFormat(2023-11-10 10:00:00,yyyy-MM-dd HH:mm:ss); }我当前时区的 Offset时差是 8 小时对于 9 小时的纽约整整差了1个小时北京早上 10 点对应早上东京 11 点。 看看Java 8是如何解决时区问题的 Java 8 推出了新的时间日期类 ZoneId、ZoneOffset、LocalDateTime、ZonedDateTime 和 DateTimeFormatter处理时区问题更简单清晰。 public static void getDataByZoneFormat8(String param, String format) throws ParseException {ZoneId zone ZoneId.of(Asia/Shanghai);ZoneId tokyoZone ZoneId.of(Asia/Tokyo);ZoneId timeZone ZoneOffset.ofHours(2);// 格式化器DateTimeFormatter dtf DateTimeFormatter.ofPattern(format);ZonedDateTime date ZonedDateTime.of(LocalDateTime.parse(param, dtf), zone);// withZone设置时区DateTimeFormatter dtfz DateTimeFormatter.ofPattern(yyyy-MM-dd HH:mm:ss Z);System.out.println(dtfz.withZone(zone).format(date));System.out.println(dtfz.withZone(tokyoZone).format(date));System.out.println(dtfz.withZone(timeZone).format(date)); }public static void main(String[] args) throws ParseException {getDataByZoneFormat8(2023-11-10 10:00:00,yyyy-MM-dd HH:mm:ss); }Asia/Shanghai对应8对应2023-11-10 10:00:00Asia/Tokyo对应9对应2023-11-10 11:00:00timeZone 是2所以对应2023-11-10 04:00:00 在处理带时区的国际化时间问题推荐使用jdk8的日期时间类 通过ZoneId定义时区使用ZonedDateTime保存时间通过withZone对DateTimeFormatter设置时区进行时间格式化得到本地时间 思路比较清晰不容易出错。 在与前端联调时报了个错java.lang.NumberFormatException: multiple points起初我以为是时间格式传的不对仔细一看不对啊。 百度一下才知道是高并发情况下SimpleDateFormat有线程安全的问题。 下面通过模拟高并发把这个问题复现一下 public static void getDataByThread(String param, String format) throws InterruptedException {ExecutorService threadPool Executors.newFixedThreadPool(5);SimpleDateFormat sdf new SimpleDateFormat(format);// 模拟并发环境开启5个并发线程for (int i 0; i 5; i) {threadPool.execute(() - {for (int j 0; j 2; j) {try {System.out.println(sdf.parse(param));} catch (ParseException e) {System.out.println(e);}}});}threadPool.shutdown();threadPool.awaitTermination(1, TimeUnit.HOURS); }果不其然报错。还将2023年转换成2220年我勒个乖乖。 在时间工具类里时间格式化我都是这样弄的啊没问题啊为啥这个不行原来是因为共用了同一个SimpleDateFormat在工具类里一个线程一个SimpleDateFormat当然没问题啦 可以通过TreadLocal 局部变量解决SimpleDateFormat的线程安全问题。 public static void getDataByThreadLocal(String time, String format) throws InterruptedException {ExecutorService threadPool Executors.newFixedThreadPool(5);ThreadLocalSimpleDateFormat sdf new ThreadLocalSimpleDateFormat() {Overrideprotected SimpleDateFormat initialValue() {return new SimpleDateFormat(format);}};// 模拟并发环境开启5个并发线程for (int i 0; i 5; i) {threadPool.execute(() - {for (int j 0; j 2; j) {try {System.out.println(sdf.get().parse(time));} catch (ParseException e) {System.out.println(e);}}});}threadPool.shutdown();threadPool.awaitTermination(1, TimeUnit.HOURS); }看一下SimpleDateFormat.parse的源码 public class SimpleDateFormat extends DateFormat {Overridepublic Date parse(String text, ParsePosition pos){CalendarBuilder calb new CalendarBuilder();Date parsedDate;try {parsedDate calb.establish(calendar).getTime();// If the year value is ambiguous,// then the two-digit year the default start yearif (ambiguousYear[0]) {if (parsedDate.before(defaultCenturyStart)) {parsedDate calb.addYear(100).establish(calendar).getTime();}}}} }class CalendarBuilder {Calendar establish(Calendar cal) {boolean weekDate isSet(WEEK_YEAR) field[WEEK_YEAR] field[YEAR];if (weekDate !cal.isWeekDateSupported()) {// Use YEAR insteadif (!isSet(YEAR)) {set(YEAR, field[MAX_FIELD WEEK_YEAR]);}weekDate false;}cal.clear();// Set the fields from the min stamp to the max stamp so that// the field resolution works in the Calendar.for (int stamp MINIMUM_USER_STAMP; stamp nextStamp; stamp) {for (int index 0; index maxFieldIndex; index) {if (field[index] stamp) {cal.set(index, field[MAX_FIELD index]);break;}}}...} }先new CalendarBuilder()通过parsedDate calb.establish(calendar).getTime();解析时间establish方法内先cal.clear()再重新构建cal整个操作没有加锁 上面几步就会导致在高并发场景下线程1正在操作一个Calendar此时线程2又来了。线程1还没来得及处理 Calendar 就被线程2清空了。 因此通过编写Date工具类一个线程一个SimpleDateFormat还是有一定道理的。 哪吒多年工作总结Java学习路线总结搬砖工逆袭Java架构师。 华为OD机试 2023B卷题库疯狂收录中刷题点这里 刷的越多抽中的概率越大每一题都有详细的答题思路、详细的代码注释、样例测试发现新题目随时更新全天CSDN在线答疑。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/928424.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

做餐饮企业网站的费用wordpress主题电影

本节,我们将跟随数据流向讲解UEP管线中的烘培光照。 文章目录 一、URP烘培光照1. 搭建场景2. 烘培光照参数设置MixedLight光照设置:直观感受 Lightmapping Settings参数设置: 3. 我们如何记录次表面光源颜色首先我们提取出相关URP代码&#…

古典密码之凯撒密码

一、原理与历史 1.1 历史背景 凯撒密码由古罗马的盖乌斯・尤利乌斯・凯撒(Gaius Julius Caesar)所创,他在军事通信中广泛使用该密码,通常采用偏移量k=3的方式,这也是 “凯撒移位” 这一名称的由来。例如,他会把命…

vi/vim文本编辑器

Vim是从 vi 发展出来的一个文本编辑器,vim 具有程序编辑的能力,可以主动的以字体颜色辨别语法的正确性 vi/vim 共分为三种模式: 命令模式、 输入模式、底线命令模式(末行模式) 命令模式:刚刚启动 vi/vim,便进入…

B3869 [GESP202309 四级] 进制转换-题解

题目 题目描述 $N$ 进制数指的是逢 $N$ 进一的计数制。例如,人们日常生活中大多使用十进制计数,而计算机底层则一般使用二进制。除此之外,八进制和十六进制在一些场合也是常用的计数制(十六进制中,一般使用字母 A…

LeetCode 139. 单词拆分(Word Break) - 动态规划深度解析 - 详解

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

电子商务网站项目预算如何用php做电商网站

WTM系列视频教程序章文字摘要:“这个视频教程我列了个提纲,分成12部分,比较详细的介绍了WTM的功能和使用方法。另外还有一些我个人对于编程的理解,当然个人理解这部分你们就当故事听,不一定对,哈哈。”“有…

设计类电子书网站比较好的网站空间

来源:智造智库【导读】国家新一代人工智能发展规划中明确提出,发展自动驾驶汽车和轨道交通系统,加强车载感知、自动驾驶、车联网、物联网等技术集成和配套,开发交通智能感知系统,形成我国自主的自动驾驶平台技术体系和…

Spring Boot 应用中构建配置文件敏感信息加密解密方案

Spring Boot 应用中构建配置文件敏感信息加密解密方案pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas&qu…

springcloud gateway Error creating bean with name bootstrapImportSelectorConfiguration:

springcloud gateway Error creating bean with name bootstrapImportSelectorConfiguration 修改 gateway 版本 从 2.2.1 ===> 2.1.3<!-- 引入 gateway 依赖 --><dependency><groupId>org.sprin…

做招聘网站需要哪些手续长沙大型网站建设公司

[css] 说说你对前端二倍图的理解&#xff1f;移动端使用二倍图比一倍图有什么好处&#xff1f; 二倍图是指单位面积下设备像素与css像素个数之比为 4 的位图。移动端使用二倍图可以在Retina屏幕下保真展示。个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃…

标准网站建设报价单六安在建项目和拟建项目

&#x1f44d;作者主页&#xff1a;进击的1 &#x1f929; 专栏链接&#xff1a;【1的Linux】 文章目录 一&#xff0c;什么是进程地址空间&#xff1f;二&#xff0c;进程地址空间是怎么设计的&#xff1f;三&#xff0c;为什么要有进程地址空间&#xff1f; 一&#xff0c;什…

网站空间控制面板iis7.0建设网站

1、查看进程 ps axuf ---静态查看所有进程#user 用户#PID 每个进程的标识符&#xff0c;父进程为1#VSZ 虚拟内存#RSS 实际内存#pts 窗口 TTY系统启动窗口# %MEM 内存#STAT 该进程的状态&#xff0c;包括&#xff1a;S 可中断睡眠Ss 父进程S< 优先级较高SN…

网站认证必须做么网络广告策划案

移动 表、表分区、LOB字段、索引、分区索引 到另一表空间 alter table 命令移动 table, partition, lob字段alter index 命令移动 索引, 分区索引移动表π 移动表&#xff08;非分区表&#xff09;&#xff1a; alter table <schema.table> move tablespace <new tab…

郑州网站开发网站制作模板网站

Hadoop中自带的hadoop-mapreduce-examples-2.7.6.jar含有一些事例&#xff0c;本文将用pi计算圆周率。若想了解其计算原理&#xff0c;参考&#xff1a;http://thinkinginhadoop.iteye.com/blog/710847。 具体步骤如下&#xff1a; 1. 启动Hadoop 切换到Hadoop安装目录下的sb…

完整教程:PyCharm接入DeepSeek,实现高效AI编程

完整教程:PyCharm接入DeepSeek,实现高效AI编程pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", …

Nginx的核心功能及实现

Nginx 核心功能与实现分析 项目概述 Nginx是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好。 核…

2025焚烧炉厂家权威推荐,技术实力与市场口碑深度解析

随着环保意识的不断提升和固体废物处理需求的持续增长,焚烧炉作为一种能实现垃圾减量化、无害化处理的关键设备,在市政、工业、医疗等多个领域的应用愈发广泛。然而,当前国内焚烧炉行业呈现出品牌数量多、质量参差不…

实验设计与分析(第6版,Montgomery)第5章析因设计引导5.7节思考题5.8 R语言解题 - 指南

实验设计与分析(第6版,Montgomery)第5章析因设计引导5.7节思考题5.8 R语言解题 - 指南2025-10-05 15:25 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important;…

创办一个网站的费用黄山自驾游攻略

随着科技的飞速发展&#xff0c;智慧园区已成为城市现代化建设的重要组成部分。山海鲸可视化智慧园区解决方案&#xff0c;作为业界领先的数字化革新方案&#xff0c;正以其独特的技术优势和丰富的应用场景&#xff0c;引领着智慧园区建设的新潮流。 本文将带大家一起了解一下…

Go 语言中的 panic 详解 - 指南

Go 语言中的 panic 详解 - 指南pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco&quo…