import java.text.SimpleDateFormat;
import java.util.Date;
class DateTime{
private SimpleDateFormat sdf = null;
public String getDate(){
this.sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
return this.sdf.format(new Date());
}
public String getDateComplete(){
this.sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒SSS毫秒");
return this.sdf.format(new Date());
}
public String getTimeStamp(){
this.sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
return this.sdf.format(new Date());
}
}
public class Test {
public static void main(String[] args) {
DateTime dt = new DateTime();
System.out.println("系统日期"+dt.getDate());
System.out.println("中文日期"+dt.getDateComplete());
System.out.println("时间戳"+dt.getTimeStamp());
}
import java.util.Date;
class DateTime{
private SimpleDateFormat sdf = null;
public String getDate(){
this.sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
return this.sdf.format(new Date());
}
public String getDateComplete(){
this.sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒SSS毫秒");
return this.sdf.format(new Date());
}
public String getTimeStamp(){
this.sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
return this.sdf.format(new Date());
}
}
public class Test {
public static void main(String[] args) {
DateTime dt = new DateTime();
System.out.println("系统日期"+dt.getDate());
System.out.println("中文日期"+dt.getDateComplete());
System.out.println("时间戳"+dt.getTimeStamp());
}
}
运行结果:
系统日期2016-07-11 17:12:03.146
中文日期2016年07月11日17时12分03秒146毫秒
时间戳20160711171203146