import java.util.Date;
import java.text.DateFormat;
import java.util.Locale;
import java.text.SimpleDateFormat;
import java.text.ParsePosition;
class DateDemo
{
public static void main(String[] args)
{
Date date=new Date();
System.out.println(date);
System.out.println(date.getTime());
DateFormat df=DateFormat.getDateInstance(DateFormat.LONG,new Locale("SIMPLE_CHINESE","CHINA"));
DateFormat df1=DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.MEDIUM);
//date.setTime(1455861256820L);
//System.out.println(DateFormat.getDateTimeInstance().format(date));
System.out.println(df1.format(date));
//SimpleDateFormate可以自定义格式,DateFormate只能SHORT MEDIUM LONG FULL几个模式。
SimpleDateFormat sdf=new SimpleDateFormat();
System.out.println(sdf.toPattern());
SimpleDateFormat sdf2=new SimpleDateFormat("'@' G yyyyy-MM-dd HH:mm:ss:S zzz");
System.out.println(sdf2.format(date));
Date date2=sdf2.parse("@ 公元 02016-02-19 15:21:09:801 CST",new ParsePosition(0)); //如果给定一个字符串,从这个里面抽取一个date对象,就得先做一个匹配这个字符串的SDF对象;用这个对象就可以匹配的抽出这个date对象了。
System.out.println(date2);
}
}
import java.text.DateFormat;
import java.util.Locale;
import java.text.SimpleDateFormat;
import java.text.ParsePosition;
class DateDemo
{
public static void main(String[] args)
{
Date date=new Date();
System.out.println(date);
System.out.println(date.getTime());
DateFormat df=DateFormat.getDateInstance(DateFormat.LONG,new Locale("SIMPLE_CHINESE","CHINA"));
DateFormat df1=DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.MEDIUM);
//date.setTime(1455861256820L);
//System.out.println(DateFormat.getDateTimeInstance().format(date));
System.out.println(df1.format(date));
//SimpleDateFormate可以自定义格式,DateFormate只能SHORT MEDIUM LONG FULL几个模式。
SimpleDateFormat sdf=new SimpleDateFormat();
System.out.println(sdf.toPattern());
SimpleDateFormat sdf2=new SimpleDateFormat("'@' G yyyyy-MM-dd HH:mm:ss:S zzz");
System.out.println(sdf2.format(date));
Date date2=sdf2.parse("@ 公元 02016-02-19 15:21:09:801 CST",new ParsePosition(0)); //如果给定一个字符串,从这个里面抽取一个date对象,就得先做一个匹配这个字符串的SDF对象;用这个对象就可以匹配的抽出这个date对象了。
System.out.println(date2);
}
}