Date -- String(格式化)
来源:互联网 发布:小额贷款业务软件 编辑:程序博客网 时间:2024/04/30 04:53
* Date --String(格式化)
* public final String format(Date date)
*
* String -- Date(解析)
* public Date parse(String source)
*
* DateForamt:可以进行日期和字符串的格式化和解析,但是由于是抽象类,所以使用具体子类SimpleDateFormat。
*
* SimpleDateFormat的构造方法:
* SimpleDateFormat():默认模式
* SimpleDateFormat(String pattern):给定的模式
* 这个模式字符串该如何写呢?
* 通过查看API,我们就找到了对应的模式
* 年 y
* 月 M
* 日 d
* 时 H
* 分 m
* 秒 s
*
* 2014年12月12日 12:12:12
*/
public class DateFormatDemo {
public static void main(String[] args) throws ParseException {
// Date -- String
// 创建日期对象
Date d = new Date();
// 创建格式化对象
// SimpleDateFormat sdf = new SimpleDateFormat();
// 给定模式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
// public final String format(Date date)
String s = sdf.format(d);
System.out.println(s);
//String -- Date
String str = "2008-08-08 12:12:12";
//在把一个字符串解析为日期的时候,请注意格式必须和给定的字符串格式匹配
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dd = sdf2.parse(str);
System.out.println(dd);
}
}
* public final String format(Date date)
*
* String -- Date(解析)
* public Date parse(String source)
*
* DateForamt:可以进行日期和字符串的格式化和解析,但是由于是抽象类,所以使用具体子类SimpleDateFormat。
*
* SimpleDateFormat的构造方法:
* SimpleDateFormat():默认模式
* SimpleDateFormat(String pattern):给定的模式
* 这个模式字符串该如何写呢?
* 通过查看API,我们就找到了对应的模式
* 年 y
* 月 M
* 日 d
* 时 H
* 分 m
* 秒 s
*
* 2014年12月12日 12:12:12
*/
public class DateFormatDemo {
public static void main(String[] args) throws ParseException {
// Date -- String
// 创建日期对象
Date d = new Date();
// 创建格式化对象
// SimpleDateFormat sdf = new SimpleDateFormat();
// 给定模式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
// public final String format(Date date)
String s = sdf.format(d);
System.out.println(s);
//String -- Date
String str = "2008-08-08 12:12:12";
//在把一个字符串解析为日期的时候,请注意格式必须和给定的字符串格式匹配
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dd = sdf2.parse(str);
System.out.println(dd);
}
}
0 0
- Date -- String(格式化)
- date转String 并且格式化
- jsp页面string转date并格式化
- date 格式化
- jstl标签的fmt:formatDate格式化日期 String to Date
- jstl fmt:formatDate格式化日期 年月 String to Date
- String to Date jstl标签的fmt:formatDate格式化日期
- String-date-Calendar转换,日期的加减格式化操作
- String-date-Calendar转换,日期的加减格式化操作
- JS 时间格式化 对Date的扩展,将 Date 转化为指定格式的String
- Date <-> String
- String & Date
- javase Date--->string ||String --->Date
- String格式化
- javascript DATE格式化
- date类型格式化
- Date()方法格式化
- 批处理中格式化Date
- 不依赖PHP7和HHVM,如何在PHP中使用强类型
- SQLite 数据库
- str.getBytes()
- Git安装配置过程-Win7
- HACM2007平方和与立方和
- Date -- String(格式化)
- 责任链模式 Chain of Responsibility Pattern
- UVa 100 3n+1问题 The 3n + 1 problem
- Oracle备份恢复-手动备份
- 数位动态规划(acm hdu 3555 ,hdu 2089,hdu 4278)
- STL之set集合容器
- requset.setAttribute(),session.setAttribute(),aplication.setAttribute()区别
- python dir()和vars()的区别
- 数据结构实验之栈三:后缀式求值