SimpleDateFormat 字符串<-->日期 按特定格式相互轉換

SimpleDateFormat經常使用方法:構造函數、pase和format 函數

做用:1.把特定格式字符串轉爲Date對象 .net

        2.    把Date對象轉爲特定格式字符串 orm

下面還附帶了些經常使用參數,省得須要用到時,又得慢慢翻API 對象


/**
日期格式化
DateFormat  SimpleDateFormat
一、parse :字符串轉化爲日期
二、format:格式化爲字符串 按指定的格式 字符串

格式: 區分大小寫
y :年
M :月
d :日
h : 1-12
H : 0-23
m :分
s :秒
S :毫秒
 *
 * @author garview
 *
 * @Date  2013-10-25下午08:48:56
 */
public class DateFormatDemo { get

 public static void main(String[] args) {
  test();
 }
 
 public static void test() {
  DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH時mm分ss秒");
  // df.parse();
  //格式化輸出日期
  System.out.println(df.format(new Date()));
  try {
   //字符串轉Date對象
   Date d = df.parse("2013年10月25日 20時59分43秒");
   System.out.println(d);
  } catch (ParseException e) {
   e.printStackTrace();
  }
 }
} io

相關文章
相關標籤/搜索