package com.sxt;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.text.SimpleAttributeSet;
/**
* Date
* @author Administrator
*
*/
public class DateDemo {
public static void main(String[] args) throws ParseException {
Date d = new Date();
long time = d.getTime();
System.out.println(“当前日期:”+time);
System.out.println(d.getYear()+1900);//年
System.out.println(d.getMonth()+1);//月
System.out.println(d.getDate());//日
System.out.println(d.getDay());//星期
System.err.println(d.getHours());//时
System.out.println(d.getMinutes());//分
System.out.println(d.getSeconds());//秒
System.out.println(time);//毫秒
//年月日
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy年MM月dd日 HH:ss”);
SimpleDateFormat sdf1 = new SimpleDateFormat(“yyyy/MM/dd HH:ss”);
SimpleDateFormat sdf2 = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
String sd = sdf.format(d);
String sd1 = sdf1.format(d);
String sd2 = sdf2.format(d);
System.out.println(sd);
System.out.println(sd1);
System.out.println(sd2);
//字符转换Date类型
String ss=”2017*3*5 12-15-33”;
SimpleDateFormat sdd = new SimpleDateFormat();
Date dd=sdd.parse(ss);
System.out.println(dd);
}
}