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

 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. R语言 基本语法

    R语言基本语法 我们将开始学习R语言编程,首先编写一个"你好,世界! 的程序. 根据需要,您可以在R语言命令提示符处编程,也可以使用R语言脚本文件编写程序. 让我们逐个体验不同之处. 命令提 ...

  2. "\r\n"与"</br>"的区别

    \n是换行,英文是New line,表示使光标到行首 \r是回车,英文是Carriage return,表示使光标下移一格 \r\n表示回车换行 \\  反斜杠 \$  美圆符 \"  双引 ...

  3. bzoj1015题解

    [题意分析] 给你一张无向图,要求支持删点和询问连通块数. [解题思路] 可以直接可持久化并查集大力艹过去. 考虑到正着删点就是倒着加点,所以并不需要可持久化.复杂度O((k+m)α(n)). [参考 ...

  4. LUOGU P3690 【模板】Link Cut Tree (lct)

    传送门 解题思路 \(lct\)就是基于实链剖分,用\(splay\)来维护每一条实链,\(lct\)的维护对象是一棵森林.\(lct\)支持很多神奇的操作: \(1.\) \(access\):这是 ...

  5. NX二次开发-UFUN输入表达式TAG,得到表达式字符串UF_MODL_ask_exp_tag_string

    NX9+VS2012 #include <uf.h> #include <uf_modl.h> UF_initialize(); //创建表达式 tag_t NewExpTag ...

  6. fasttext的基本使用 java 、python为例子

    fasttext的基本使用 java .python为例子 今天早上在地铁上看到知乎上看到有人使用fasttext进行文本分类,到公司试了下情况在GitHub上找了下,最开始是c++版本的实现,不过有 ...

  7. var 更明确地表示一个变量被设置为零值

    创建一个变量并被初始化其为零值,习惯使用关键字var.这种做法是为了更明确地表示一个变量被设置为零值. 如果变量被初始化为某个非零值,就配合结构字面量和短变量操作符来创建变量. 零值 数值类型:0 字 ...

  8. jdk linux配置

    用文本编辑器打开/etc/profile 在profile文件末尾加入: export JAVA_HOME=/usr/share/jdk1.6.0_14 export PATH=$JAVA_HOME/ ...

  9. CodeForces-1244C-The Football Season-思维

    The football season has just ended in Berland. According to the rules of Berland football, each matc ...

  10. .net与C#

    一..net包含什么? 1.包含庞大的代码库,分为多个模块,可以自主选择 2.定义了基本的类型,被称为通用类型系统(CTS,common type system): 3.包含.NET公共语言运行库(C ...