日期时间的格式化和解析:

 public class DateTimeFormatterTest {
     /**
      * 时间日期格式化
      * @param args
      */
     public static void main(String[] args) {

         LocalDateTime localDateTime = LocalDateTime.now();
         //方式一2019-07-04T10:27:28.453
         DateTimeFormatter isoLocalDateTime = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
         String format = isoLocalDateTime.format(localDateTime);
         System.out.println(format);

         //方式二
         // SHORT:19-7-4 上午10:42
         // LONG:2019年7月4日 上午10时43分35秒
         // MEDIUM:2019-7-4 10:44:11
         DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM);
         String format1 = formatter.format(localDateTime);
         System.out.println(format1);

         //方式三
         // 自定义:2019-7-4 10:46:23
         DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyy-MM-dd HH-mm-ss");
         String format2 = formatter1.format(localDateTime);
         System.out.println(format2);

         //解析:{},ISO resolved to 2019-07-04T10:49:46
         TemporalAccessor parse = formatter1.parse("2019-07-04 10-49-46");
         System.out.println(parse);

     }
 }

java_DateTimeFormatter的更多相关文章

随机推荐

  1. 【Bootstrap】 框架 栅格布局系统设计原理

    前提条件(Bootstrap 自带) 首先使用这个布局之前要定义一下代码: 这行代码如果不懂,可以搜索一下,总之大致意思就是,被定义的元素的内边距和边框不再会增加它的宽度,不加入的话排版会有问题. 不 ...

  2. spring注解方式配置以及spring4的泛型注入 (4)

    目录 一.@Controller 注解控制层(action) 二.@Service 注解服务层 三.@Repository 持久层 四.spring4的泛型注入测试 1 创建两个实体User和Role ...

  3. c# ToString()格式大全(转)

    stringstr1 =string.Format("{0:N1}",56789);               //result: 56,789.0stringstr2 =str ...

  4. Java-Class-C:org.springframework.http.HttpEntity

    ylbtech-Java-Class-C:org.springframework.http.HttpEntity 1.返回顶部 1.1. import org.springframework.http ...

  5. 基于Netty的RPC架构学习笔记(五):netty线程模型源码分析(二)

    文章目录 小技巧(如何看开源框架的源码) 源码解析 阅读源码技巧 打印查看 通过打断点调试 查看调用栈 小技巧(如何看开源框架的源码) 一断点 二打印 三看调用栈 四搜索 源码解析 //设置nioso ...

  6. day 87 DjangoRestFramework学习一之restful规范、APIview、解析器组件、Postman等

    DjangoRestFramework学习一之restful规范.APIview.解析器组件.Postman等   本节目录 一 预备知识 二 restful规范 三 DRF的APIView和解析器组 ...

  7. Python3 From Zero——{最初的意识:008~初级实例演练}

    一.构显国际橡棋8x8棋盘 #!/usr/bin/env python3 #-*- coding:utf-8 -*- color_0="\033[41m \033[00m" col ...

  8. 剑指offer——29顺时针打印矩阵

    题目描述 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下4 X 4矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数 ...

  9. Python-docx库的使用

    from docx import Document from docx.shared import Inches document = Document() document.add_heading( ...

  10. jquery.js和jquery.min.js的区别和springboot整合echarts.min.js

    1.区别:jquery官网提供2种jQuery的下载,一种是jquery.js另一种是jquery.min.js文件名不一定完全相同,但通常情况下:jquery.js是完整的未压缩的jQuery库,文 ...