java_DateTimeFormatter
日期时间的格式化和解析:
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的更多相关文章
随机推荐
- thinkphp session支持
系统提供了Session管理和操作的完善支持,全部操作可以通过一个内置的session函数完成,该函数可以完成Session的设置.获取.删除和管理操作. session初始化设置 如果session ...
- PHP headers_sent() 函数
定义和用法 headers_sent() 函数检查 HTTP 报头是否发送/已发送到何处. 如果报头已发送,该函数返回 TRUE,否则返回 FALSE. 语法 headers_sent(file,li ...
- tesserocr与pytesseract模块的使用
1.tesserocr的使用 #从文件识别图像字符 In [7]: tesserocr.file_to_text('image.png') Out[7]: 'Python3WebSpider\n\n' ...
- POJ-1836-Alignment-双向LIS(最长上升子序列)(LIS+LSD)+dp
In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are al ...
- mycat-zookeepr--mycatweb
##############################mycat镜像############################## 5-1 创mycat镜像 wget http://dl.myca ...
- idea引入项目下所有文件(ps:包括静态文件夹)
打开项目的目录结构 点击finish 最后删除目录下多余的src就可以了
- vue中解决拖动和点击事件的冲突
BUG说明: 鼠标上下方向拖拽,如果松开时鼠标位于悬浮按钮上会默认执行click事件,经验证,click事件与mouse事件的执行顺序为onmousedown =>onmouseup => ...
- HDFS HA
- 【笔记篇】不普及向——莫比乌斯反演学习笔记 && 栗题HAOI2011 Problem B
Part0 广告(当然没有广告费) P.S. 这篇文章是边学着边用Typora写的...学完了题A了blog也就呼之欲出了~有latex化式子也非常方便...非常建议喜欢Markdown的dalao们 ...
- 【JZOJ6370】基础 fake 练习题
description 装饰者坐在树荫下听着长者讲述以前的故事: 大神 yk 非常喜欢树,便钦点班里的 n 个小蒟蒻站在一棵 n 个点以 1 为根的树上,并且每个点上恰好有 1 个小蒟蒻. 大神 yk ...