Date類型與毫秒值之間的轉化,dateformat的解析和格式化,SimpleDateFormat的解析和格式化

日期:orm

DTAE 表示到一個毫秒值,距離1970年7月1日的毫秒值。字符串

Canlendar用來操做日曆時間的類get

DATAformat解析時間日期的字符串。form

1 毫秒值與date類型之間的轉化:date

毫秒值轉化爲時間類型:方法

Long time=2132132131231;im

經過構造方法:數據

Date d=new Date(time);時間

經過settime轉化。字符

New Date.settime(time);

Date轉化爲毫秒值:

Data.Gettime()

2 時間類型數據的解析爲字符串類型

用dateformat

DateFormat dft=dateformat.getDateInstance(x);//x爲dateformat的字段摘要

String str=dft.DateFormat();

用simpleDateFormat,此類爲解析自定義格式的時間格式,轉成String字符串

String str=」2014/06/11/12:56」

Simpledateformat slf=new simpledateformat(x);x爲解析的格式:「yyyy/MM/dd/HH:mm」

3字符串類型轉化爲時間類型

1 用simpledateformat 格式化自定義格式的字符串

String str="2014/4/11";

SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd");

System.out.println(sdf.parse(str));

2 用dataformat格式化已有格式的字符串

String str="2014年4月11日";

DateFormat dft=DateFormat.getDateInstance(DateFormat.LONG);

System.out.println(dft.parse(str));

相關文章
相關標籤/搜索