java43
自定义日期格式
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
public class 自定义日期格式 {
public static void main(String[] args) throws ParseException {
//1.日期格式化(将日期形式化为自己想要的形式)
Date date = new Date();
System.out.println(date);
DateFormat df = DateFormat.getInstance();
String t = df.format(date);
System.out.println(t);
System.out.println("------------------");
【Sat Aug 10 11:04:18 CST 2019
19-8-10 上午11:04
------------------】
//长日期
//短日期
DateFormat df2 = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
String t2 = df2.format(date);
System.out.println(t2);
System.out.println("--------------------");
【19-8-10 上午11:04
--------------------】
DateFormat df3 = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG);
String t3 = df3.format(date);
System.out.println(t3);
System.out.println("-------------------");
【2019年8月10日 上午11时04分18秒
-------------------】
//只显示时间
DateFormat df4 = DateFormat.getTimeInstance();
String t4 = df4.format(date);
System.out.println(t4);
System.out.println("-------------------");
【11:04:18
-------------------】
//将字符串转换成日期
DateFormat df5 = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
String res = "2019年8月10日 上午10时48分07秒";
Date date2 = df5.parse(res);
System.out.println(date2);
}
}
【Sat Aug 10 10:48:07 CST 2019】
自定义日期格式
import java.text.SimpleDateFormat;
import java.util.Date;
public class 自定义日期格式 {
public static void main(String[] args) {
Date date = new Date();
SimpleDateFormat sd = new SimpleDateFormat();
//定义成想要的模式
sd.applyPattern("MM/dd");
String res = sd.format(date);
System.out.println(res);
}
}
【08/10】
java43的更多相关文章
随机推荐
- Vue项目入门实例
前言 本文记录Vue2.x + Element-UI + TypeScript语法入门实例 为什么要用TypeScript? 1.TypeScript是JavaScript的超集,利用es6语法,实现 ...
- STM32移植FreeRTOS(1)
"STM32F103VET6<_>FreeRTOS" 1.项目功能实现 1)LED灯定时闪烁 2)KEY按键检测 3)FreeRTOS任务创建 4)串口输出程序运行状态 ...
- Union-Find算法应用
上篇文章很多读者对于 Union-Find 算法的应用表示很感兴趣,这篇文章就拿几道 LeetCode 题目来讲讲这个算法的巧妙用法. 首先,复习一下,Union-Find 算法解决的是图的动态连通性 ...
- 震惊!很多人都不知道 CSS Grid 框架早就有了!
前言 写作本文起源于知乎的一个问题:[CSS Grid 布局那么好,为什么至今没有人开发出基于 Grid 布局的前端框架呢?] 这篇文章拖沓了两个月,是因为真的不知道从哪里说好.这个问题的所有回答几乎 ...
- 01 . Vue简介,原理,环境安装
简介 vue是一个JavaMVVM库,是一套用于构建用户界面的渐进式框架,是初创项目的首选前端框架.它是以数据驱动和组件化的思想构建的,采用自底向上增量开发的设计.它是轻量级的,它有很多独立的功能或库 ...
- 【涂鸦物联网足迹】API及SDK介绍
前序系列文章>>> [涂鸦物联网足迹]物联网主流通信方式 我们系列文章,都会围绕如何完成一款智能"隔空接吻机"的开发.希望能帮到各异地恋or异国恋的情侣们! 本文 ...
- nginx&http 第三章 ngx 事件event epoll 处理
1. epoll模块命令集 ngx_epoll_commands epoll模块上下文 ngx_epoll_module_ctx epoll模块配置 ngx_epoll_module static ...
- tcp 客户端 synack的接收 以及 相互connect
接收入口 tcp_v4_rcv |--> tcp_v4_do_rcv |-> tcp_rcv_state_process ...
- Spring之事务源码
对@Transactional注解的类进行动态代理 同前文<Spring AOP源码分析>中分析动态代理入口一样,都是在initializeBean时执行. Object exposedO ...
- mysql 5.7添加server_audit 安全审计功能
mysql 5.7添加server_audit 安全审计功能 一.根据链接下载插件 参考链接下载 http://blog.itpub.net/31441024/viewspace-2213103 l ...