java 格式化日期(DateFormat)
import java.text.DateFormat;
import java.util.Date; /**
* 格式化时间类 DateFormat.FULL = 0
* DateFormat.DEFAULT = 2
* DateFormat.LONG = 1
* DateFormat.MEDIUM = 2
* DateFormat.SHORT = 3
*/
public class Test { public static void main(String[] args) {
Date d = new Date();
String s; /* Date类的格式: Wed Jul 02 14:54:45 CST 2014 */
System.out.println(d); System.out.println("******************************************"); /* getDateInstance() */
/* 输出格式: 2014-7-2 */
s = DateFormat.getDateInstance().format(d);
System.out.println(s); /* 输出格式: 2014-7-2 */
s = DateFormat.getDateInstance(DateFormat.DEFAULT).format(d);
System.out.println(s); /* 输出格式: 2014年7月2日 星期三 */
s = DateFormat.getDateInstance(DateFormat.FULL).format(d);
System.out.println(s); /* 输出格式: 2014-7-2 */
s = DateFormat.getDateInstance(DateFormat.MEDIUM).format(d);
System.out.println(s); /* 输出格式: 14-7-2 */
s = DateFormat.getDateInstance(DateFormat.SHORT).format(d);
System.out.println(s); /* 输出格式: 2014-07-02 02:54:45 */
java.text.DateFormat format1 = new java.text.SimpleDateFormat(
"yyyy-MM-dd hh:mm:ss");
s = format1.format(new Date());
System.out.println(s); /* 输出格式: 2014-07-02 02:54:45 */
System.out.println((new java.text.SimpleDateFormat(
"yyyy-MM-dd hh:mm:ss")).format(new Date())); /* 输出格式: 20140702025445** */
java.text.DateFormat format2 = new java.text.SimpleDateFormat(
"yyyyMMddhhmmss");
s = format2.format(new Date());
System.out.println(s);
} }
java 格式化日期(DateFormat)的更多相关文章
- Java 格式化日期、时间
有三种方法可以格式化日期.时间. 1.使用DateFormat类 获取DateFormat实例: DateFormat.getDateInstance() 只能格式化日期 2019年5 ...
- Java格式化日期的三种方式
1)借助DateFormat类: public String toString(Date d) { SimpleDateFormat sdf = new SimpleDateFormat(“yyyy- ...
- java 格式化日期
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); simpleDat ...
- Java基础-日期格式化DateFormat类简介
Java基础-日期格式化DateFormat类简介 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.DateFormat类概述 DateFormat 是日期/时间格式化子类的抽象 ...
- 详解Java中格式化日期的DateFormat与SimpleDateFormat类
DateFormat其本身是一个抽象类,SimpleDateFormat 类是DateFormat类的子类,一般情况下来讲DateFormat类很少会直接使用,而都使用SimpleDateFormat ...
- JAVA格式化时间日期
JAVA格式化时间日期 import java.util.Date; import java.text.DateFormat; /** * 格式化时间类 * DateFormat.FULL = 0 * ...
- Java链接MySQL练习题:格式化日期、性别;避免代码注入
一.查询人员名单,按序号 姓名 性格(男或女) 民族(某族) 生日(年月日)输出 import java.sql.*; import java.text.SimpleDateFormat; publi ...
- Java进阶(二十八)SimpleDateFormat格式化日期问题
SimpleDateFormat格式化日期问题 前言 发现一个问题,经过以下语句处理后,发现12:27:45转换后成为了00:27:45. DateFormat df = null; if(DATE1 ...
- java的日期格式化
原博客地址: http://blog.csdn.net/yangbobo1992/article/details/9965105 日期格式: 时间日期标识符: yyyy:年 MM:月 dd:日 hh: ...
随机推荐
- page74-泛型可迭代的基础集合数据类型的API-Bag+Queue+Stack
[泛型可迭代的基础集合数据类型的API] 背包:就是一种不支持从中删除元素的集合数据类型——它的目的就是帮助用例收集元素并迭代遍历所有收集到的元素.(用例也可以检查背包是否为空, 或者获取背包中元素的 ...
- 典型的字符串处理代码(page50)
Page50: public class TypicalString{//典型的字符串处理代码 public static boolean isPlalindrom(String s){//判断字符串 ...
- js实现hashtable的赋值、取值、遍历
哈希表(Hashtable)这个概率应该是#c里面的概念,用来赋值.取值.遍历.排序操作提高效率.想起这个东西其实使我们以前经常遇到这样的面试题,一个很大的数组可能有100000个,如何快速知道它里面 ...
- macOS10.12允许所有来源设置
如何调出允许所有来源呢? 很简单一行命令搞定 调出允许所有来源 1.打开终端执行命令 sudo spctl --master-disable 2.你在打开偏好设置--> 安全与隐私 好了赶快 ...
- NodeJS学习之网络操作
NodeJS -- 网络操作 使用NodeJS内置的http模块简单实现HTTP服务器 var http = require('http'); http.createServer(function(r ...
- 初识--Ajax & Json
1,AJAX是一种进行页面局部异步刷新技术. 用AJAX向服务器发送请求和获得服务器返回的数据并更新到页面中. 不是刷新整个页面,而是在HTML页面中使用JavaScript创建XMLHTTPRequ ...
- Table of Contents - MyBatis
Getting Started with MyBatis Hello World Integration with Spring Bootstrapping MyBatis Configuring M ...
- ruby学习--block
#当前块 class Block def a_method return yield if block_given? 'no block' end end obj=Block.new puts &qu ...
- vs2013发布时: sgen.exe 已退出 代码为 1
出现这个错的时候,有查网上的.自己也亲试了一下,注意两个地方就行. 红色框里设成这样的值就OK了!
- SQLSERVER中按年月分组
SQLSERVER中按年月分组 一个表有三个字段id,dt,d 分别存放id,时间,数值 id dt d 1 2004-08-11 12:12:00.000 9 2 2005-09- ...