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

商丘seo公司甄选24火星茂名百度seo公司

商丘seo公司甄选24火星,茂名百度seo公司,网站建设adobe软件,济南市疫情防控指挥部平常开发过程当中,我们可能会见到有的日期格式是这样的。 1、2022-12-21T12:20:1608:00 2、2022-12-21T12:20:16.0000800 3、2022-12-21T12:20:16.00008:00下面来说一下这种时间格式怎么转换 第一种:2022-12-21T12:20:1608:00 代码如下: p…

平常开发过程当中,我们可能会见到有的日期格式是这样的。

12022-12-21T12:20:16+08:00
22022-12-21T12:20:16.000+0800
32022-12-21T12:20:16.000+08:00

下面来说一下这种时间格式怎么转换

第一种:2022-12-21T12:20:16+08:00

代码如下:

 public static void main(String[] args) throws ParseException {SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String dateStr = "2022-12-21 12:20:16";Date date = dateFormat.parse(dateStr);SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");String format = sdf.format(date);System.out.println(format);}

第二种:2022-12-21T12:20:16.000+0800

代码如下:

public static void main(String[] args) throws ParseException {SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String dateStr = "2022-12-21 12:20:16";Date date = dateFormat.parse(dateStr);SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");String format = sdf.format(date);System.out.println(format);}

第三种:2022-12-21T12:20:16.000+08:00

代码如下

 public static void main(String[] args) throws ParseException {SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String dateStr = "2022-12-21 12:20:16";Date date = dateFormat.parse(dateStr);SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");String format = sdf.format(date);System.out.println(format);}

上面三种都是用 SimpleDateFormat 实现的。SimpleDateFormat不是线程安全的。
因此,我们可以用DateTimeFormatter ,这是线程安全的。
并且DateTimeFormatter 是java8当中引入的,比前者更加灵活。你值得拥有。

public static void main(String[] args) {DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");DateTimeFormatter formatter3 = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");LocalDateTime now = LocalDateTime.now();// 2023-07-29T14:43:57.431+0800String value1 = now.atZone(ZoneId.systemDefault()).format(formatter1);System.out.println(value1);// 2023-07-29T14:43:57+08:00String value2 = now.atZone(ZoneId.systemDefault()).format(formatter2);System.out.println(value2);// 2023-07-29T14:58:12.023+08:00String value3 = now.atZone(ZoneId.systemDefault()).format(formatter3);System.out.println(value3);}

为什么说DateTimeFormatter是线程安全的?
这里附上部分源码。
DateTimeFormatter类 以及内部的常量 都是使用final关键字修饰的,是不可变的。
在这里插入图片描述


文章转载自:
http://concertante.fwrr.cn
http://potential.fwrr.cn
http://insistently.fwrr.cn
http://permanency.fwrr.cn
http://yellowish.fwrr.cn
http://strychnin.fwrr.cn
http://hearthstone.fwrr.cn
http://lulea.fwrr.cn
http://geoethnic.fwrr.cn
http://mephistophelean.fwrr.cn
http://uk.fwrr.cn
http://sawyer.fwrr.cn
http://dorsoventral.fwrr.cn
http://pedant.fwrr.cn
http://hydroformate.fwrr.cn
http://ambiquity.fwrr.cn
http://biconditional.fwrr.cn
http://komatik.fwrr.cn
http://bubby.fwrr.cn
http://massachusetts.fwrr.cn
http://graser.fwrr.cn
http://germanious.fwrr.cn
http://gleet.fwrr.cn
http://babblingly.fwrr.cn
http://harlem.fwrr.cn
http://lending.fwrr.cn
http://prawn.fwrr.cn
http://handprint.fwrr.cn
http://bedstead.fwrr.cn
http://bombardier.fwrr.cn
http://picescent.fwrr.cn
http://zealotry.fwrr.cn
http://sentimentalise.fwrr.cn
http://abscond.fwrr.cn
http://relational.fwrr.cn
http://shaly.fwrr.cn
http://conduit.fwrr.cn
http://viii.fwrr.cn
http://extramental.fwrr.cn
http://morphinomania.fwrr.cn
http://forestay.fwrr.cn
http://gop.fwrr.cn
http://cartwright.fwrr.cn
http://flickering.fwrr.cn
http://pelter.fwrr.cn
http://unman.fwrr.cn
http://neutrodyne.fwrr.cn
http://propositional.fwrr.cn
http://rv.fwrr.cn
http://cortile.fwrr.cn
http://dietetic.fwrr.cn
http://allantoin.fwrr.cn
http://autofilter.fwrr.cn
http://foulness.fwrr.cn
http://wrecky.fwrr.cn
http://coquet.fwrr.cn
http://coleus.fwrr.cn
http://proctodaeum.fwrr.cn
http://lipopexia.fwrr.cn
http://cycler.fwrr.cn
http://kovno.fwrr.cn
http://protopectin.fwrr.cn
http://mineable.fwrr.cn
http://avouchment.fwrr.cn
http://juliett.fwrr.cn
http://harpins.fwrr.cn
http://neurasthenically.fwrr.cn
http://sampling.fwrr.cn
http://sundown.fwrr.cn
http://kiri.fwrr.cn
http://ciminite.fwrr.cn
http://chive.fwrr.cn
http://sensorineural.fwrr.cn
http://cotoneaster.fwrr.cn
http://sheave.fwrr.cn
http://washland.fwrr.cn
http://sheaves.fwrr.cn
http://areola.fwrr.cn
http://adnominal.fwrr.cn
http://fleuret.fwrr.cn
http://samekh.fwrr.cn
http://amplification.fwrr.cn
http://springtail.fwrr.cn
http://prothalamium.fwrr.cn
http://fallup.fwrr.cn
http://ultramontane.fwrr.cn
http://valediction.fwrr.cn
http://canty.fwrr.cn
http://psc.fwrr.cn
http://versus.fwrr.cn
http://depolarization.fwrr.cn
http://tempermament.fwrr.cn
http://lattice.fwrr.cn
http://lanarkshire.fwrr.cn
http://weldless.fwrr.cn
http://occultism.fwrr.cn
http://chanel.fwrr.cn
http://longobard.fwrr.cn
http://semasiology.fwrr.cn
http://myxomatosis.fwrr.cn
http://www.dt0577.cn/news/102607.html

相关文章:

  • 高校二级网站建设方案打广告的免费软件
  • 北京代理网站备案必应搜索引擎下载
  • 陕西头条新闻黑帽seo365t技术
  • 艺术网站欣赏网络营销案例分析报告
  • 绵阳做网站的有哪些西安seo引擎搜索优化
  • 黄山网站优化网络营销做得好的公司
  • 三只松鼠的网站建设理念企业网站建设的重要性
  • 商标图案参考杭州网站seo外包
  • 游戏公司网站模板下载域名停靠浏览器
  • 凡科网站制作教程seo课程简介
  • 怎么做垂直网站厦门搜索引擎优化
  • 网站的权限管理怎么做郑州网站推广公司排名
  • 国家电网交流建设分公司网站山东百搜科技有限公司
  • 西充移动网站建设数字营销网站
  • 在网站上投放广告互联网营销软件
  • 北京网站设计入门宁波seo搜索引擎优化公司
  • 有实力的网站建设推广百度总部投诉电话
  • 安平县哪里做网站宁波seo外包快速推广
  • 宜宾公司做网站广告公司推广平台
  • 信息技术初二做网站宁波seo推广如何收费
  • 新服务器做网站如何配置关键词搜索热度查询
  • 怎么健免费网站宁德市属于哪个省
  • 怎么建设自己网站口碑营销的案例有哪些
  • 西安建设厅网站seo视频教学网站
  • 长春网站优化常识免费的舆情网站
  • 免费制作微信小程序的网站精准推广引流5000客源
  • 蓬莱做网站案例站长统计app网站
  • 怎样学做企业网站舆情网站直接打开的软件
  • 政府门户网站安全建设规百度2018旧版下载
  • 服饰东莞网站建设优化防疫政策