Java常用类之日期类Date DateFormat and SimpleDateFormat
来源:互联网 发布:mac os破解版 编辑:程序博客网 时间:2024/05/16 07:48
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class DateDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Date date = new Date();
System.out.println(date);
// 返回的是毫秒数
System.out.println(date.getTime());
// 设置时间
date.setTime(1498571779444L);
System.out.println(date);
DateFormat df1 = null;
DateFormat df2 = null;
// 产生dateform的子类对象
/*
* df1=DateFormat.getDateInstance();
* df2=DateFormat.getDateTimeInstance(); //日期
* System.out.println("Date:"+df1.format(date)); //日期+时间
* System.out.println("DateTime:"+df2.format(date));
*/
df1 = DateFormat.getDateInstance(DateFormat.FULL, new Locale("zh", "CN"));
df2 = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, new Locale("zh", "CN"));
System.out.println("Date:" + df1.format(date));
System.out.println("DateTime:" + df2.format(date));
// 自定义格式指定日期格式化输出SimpleDateFormat
String strDate = "2010-10-19 10:11:30.345";
Date d = null;
// 模板
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy年MM月dd日 HH-mm-ss.SSS");
//
try {
// 把日期字符串中的日期部分抽取出来生成一个Date对象
d = sdf.parse(strDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(d);
// 把日期按指定的模板格式格式化输出为字符串
String str = sdf1.format(d);
System.out.println(str);
}
}
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class DateDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Date date = new Date();
System.out.println(date);
// 返回的是毫秒数
System.out.println(date.getTime());
// 设置时间
date.setTime(1498571779444L);
System.out.println(date);
DateFormat df1 = null;
DateFormat df2 = null;
// 产生dateform的子类对象
/*
* df1=DateFormat.getDateInstance();
* df2=DateFormat.getDateTimeInstance(); //日期
* System.out.println("Date:"+df1.format(date)); //日期+时间
* System.out.println("DateTime:"+df2.format(date));
*/
df1 = DateFormat.getDateInstance(DateFormat.FULL, new Locale("zh", "CN"));
df2 = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, new Locale("zh", "CN"));
System.out.println("Date:" + df1.format(date));
System.out.println("DateTime:" + df2.format(date));
// 自定义格式指定日期格式化输出SimpleDateFormat
String strDate = "2010-10-19 10:11:30.345";
Date d = null;
// 模板
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy年MM月dd日 HH-mm-ss.SSS");
//
try {
// 把日期字符串中的日期部分抽取出来生成一个Date对象
d = sdf.parse(strDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(d);
// 把日期按指定的模板格式格式化输出为字符串
String str = sdf1.format(d);
System.out.println(str);
}
}
阅读全文
0 0
- Java常用类之日期类Date DateFormat and SimpleDateFormat
- 关于java日期类Date,DateFormat,SimpleDateFormat,Calendar总结
- java常用类库续1(日期操作类Date、Calendar、DateFormat、SimpleDateFormat、Math与Random类)
- java常用类库续1(日期操作类Date、Calendar、DateFormat、SimpleDateFormat、Math与Random类)
- 日期操作类(Date、Calendar、DateFormat、SimpleDateFormat)
- Java日期操作类(DateFormat、SimpleDateFormat)
- java 日期操作类 DateFormat 和 SimpleDateFormat
- java学习之日期类(3):Date类,DateFormat类,SimpleDateFormat类的说明与使用
- Date、Calendar、DateFormat、SimpleDateFormat类
- 日期处理类总结:Date/Calendar/GregorianCalendar/DateFormat/SimpleDateFormat类
- Java常用类库之时间操作类——Date、Calendar、DateFormat、SimpleDateFormat及实例操作
- java日期处理类总结:Date/Calendar/GregorianCalendar/DateFormat/SimpleDateFormat类
- java日期处理类总结:Date/Calendar/GregorianCalendar/DateFormat/SimpleDateFormat类 .
- java日期处理类总结:Date/Calendar/GregorianCalendar/DateFormat/SimpleDateFormat类
- java日期处理类总结:Date/Calendar/GregorianCalendar/DateFormat/SimpleDateFormat类
- java日期处理类总结:Date/Calendar/GregorianCalendar/DateFormat/SimpleDateFormat类
- JAVA日期处理类总结:Date/Calendar/GregorianCalendar/DateFormat/SimpleDateFormat类
- java日期处理类总结:Date/Calendar/GregorianCalendar/DateFormat/SimpleDateFormat类
- 前端工程师如何定位自己等级层次
- 万能适配器(二)
- 分析一下到底是上升沿还是下降沿读写数据
- Redis详细介绍
- Python2.7抓取豆瓣美女图片
- Java常用类之日期类Date DateFormat and SimpleDateFormat
- Reactjs中的属性(this.props)
- Java集合之ArrayList
- chapter02
- crackMe的逆向分析
- 【Android学习】网络通信----以HttpURLConnection Post请求为例
- UVa Spreading the Wealth-11300(数学推导+中位数)
- AtomicReference(无锁的对象引用)与AtomicStampedReference与(带有时间戳的对象引用)
- JAVA学习日记----------