package com.qunar.basicJava.javase.p11CommonlyUsedClass;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
/**
* Author: libin.chen@qunar.com Date: 14-5-21 11:14
*/
public class DateDemo {
public static void main(String[] args) throws ParseException {
Date date = new Date();
System.out.println("当前时间 : " + date);
//--------------------------
Calendar calendar = null;
calendar = new GregorianCalendar();
System.out.println("年 : " + calendar.get(Calendar.YEAR));
DateFormat dateFormat1 = DateFormat.getDateInstance(DateFormat.YEAR_FIELD, new Locale("zh", "CN"));
DateFormat dateFormat2 = DateFormat.getDateTimeInstance(DateFormat.YEAR_FIELD, DateFormat.ERA_FIELD, new Locale("zh", "CN"));
System.out.println("DATE : " + dateFormat1.format(new Date()));
System.out.println("DATETIME : " + dateFormat2.format(new Date()));
String strDate = "2008-10-19 10:11:30.345"; // 定义日期时间的字符串
String pat = "yyyy-MM-dd HH:mm:ss.SSS"; // 定义模板
SimpleDateFormat sdf = new SimpleDateFormat(pat); // 实例化模板对象
Date d = sdf.parse(strDate); // 将给定字符串的日期提取出来
System.out.print("\nSimpleDateFormat : ");
System.out.println(d);
System.out.println(sdf.format(d));
}
}
Date And Calendar And SimpleDateFormat 与 国际化
转载于:https://www.cnblogs.com/robbychan/p/3786747.html